package com.caigou.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.caigou.bean.cms.entity.*;
import com.caigou.bean.cms.param.*;
import com.caigou.bean.exam.entity.Users;
import com.caigou.bean.vo.*;
import com.caigou.component.*;
import com.caigou.constant.NewsConstant;
import com.caigou.enums.Constant;
import com.caigou.enums.ResponseEnum;
import com.caigou.exception.DuplicateDataException;
import com.caigou.mapper.cms.*;
import com.caigou.pojo.*;
import com.caigou.service.*;
import com.caigou.util.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.aop.framework.AopContext;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;

@Slf4j
@Service
public class ArticleServiceImpl implements ArticleService {

    @Resource
    private ArticleComponent articleComponent;// 文章操作组件
    @Resource
    private RedisStringComponent redisStringComponent;// String
    @Resource
    private RedisObjectComponent redisObjectComponent;// Object缓存组件
    @Resource
    private DeleteFileComponent deleteFileComponent;// 静态资源删除组件
    @Resource
    private ChannelComponent channelComponent;// 频道操作组件

    @Resource
    private ArticleProceedInfoService articleProceedInfoService;// 文章报纸/微信/电子书关联信息
    @Resource
    private ArticleTitleService articleTitleService;// 文章标题获取
    @Resource
    private ArticleAdjunctService articleAdjunctService;// 文章附件获取
    @Resource
    private ArticleLawService articleLawService;// 法律基础信息
    @Resource
    private ArticleCaseService articleCaseService;// 案例数据信息
    @Resource
    private ArticleImageService articleImageService;// 图集数据信息
    @Resource
    private ArticleAudioService articleAudioService;// 音频信息数据
    @Resource
    private ArticleProductService articleProductService;// 产品信息数据
    @Resource
    private ArticleBookService articleBookService;// 图书信息数据
    @Resource
    private ArticleSpecialLayoutService articleSpecialLayoutService;// 专题布局信息
    @Resource
    private ArticleSpecialDataService articleSpecialDataService;// 专题数据结构
    @Resource
    private ArticleSpecialAnnotationService articleSpecialAnnotationService;// 专题注释条
    @Resource
    private ArticleInformationService articleInformationService;//文章新闻、内控制度、采购文件范本、采购合同范本、处理信息库(名库)、词库(政采百科)
    @Resource
    private AuditDataService auditDataService;// 操作记录获取
    @Resource
    private ChannelDataService channelDataService;// 频道内容表
    @Resource
    private ChannelConfigService channelConfigService;// 频道配置表
    @Resource
    private IUserBaseInfoService userBaseInfoService;// 用户信息获取
    @Resource
    private ArticlePromoterService articlePromoterService;// 作者信息数据
    @Resource
    private ArticleDictionaryService articleDictionaryService;// 字典信息获取
    @Resource
    private ICommentService commentService;// 评论
    @Resource
    private ArticleKeywordService articleKeywordService;

    @Resource
    private ArticleMapper articleMapper;// 文章主表






    @Resource
    private OSSComponent ossComponent;// OSS上传组件
    @Resource
    private RabbitProducer rabbitProducer;// MQ消息
    @Resource
    private SnowflakeComponent snowflakeComponent;// 雪花UUID组件

    @Resource
    private HtmlDetailBuilderComponent htmlDetailBuilderComponent;// 模板生成组件(文章静态页)
    @Resource
    private HtmlHomePageBuilderComponent htmlHomePageBuilderComponent;// 模板生成组件(文章静态页)
    @Resource
    private HtmlBuilderComponent htmlBuilderComponent;
    @Resource
    private HtmlBuildImageComponent htmlBuildImageComponent;
    // service





    @Resource
    private ArticleHtmlService articleHtmlService;// 文章静态资源生成标识



    @Resource
    private ArticleLawEntryService articleLawEntryService;// 法律词条信息







    @Resource
    private ChannelService channelService;// 频道




    @Resource
    private CopyrightMapper copyrightMapper;

    // mapper

    @Resource
    private ArticleKeywordMapper articleKeywordMapper;// 关键字
    @Resource
    private ArticleStatisticsMapper articleStatisticsMapper;// 统计量
    @Resource
    private ChannelMapper channelMapper;
    @Resource
    private ChannelConfigMapper channelConfigMapper;
    @Resource
    private ChannelDataMapper channelDataMapper;
    @Resource
    private ArticleTitleMapper articleTitleMapper;
    @Resource
    private ChannelDataInfoMapper channelDataInfoMapper;
    @Resource
    private ArticleStatisticsDayMapper articleStatisticsDayMapper;


    @Resource
    private TemplateComponent templateComponent;

    @Resource
    private AmqpTemplate amqpTemplate;

    @Value("${domain}")
    private String domain;

    @Value("${mobile.info}")
    private String info;
    @Value("${mobile.case}")
    private String caseUrl;
    @Value("${mobile.law}")
    private String law;
    @Value("${mobile.yllzc}")
    private String yllzc;
    @Value("${mobile.atlas}")
    private String atlas;
    @Value("${mobile.special}")
    private String special;

    @Override
    public Result loadArticleReleaseChannelStatus(ArticleParam param) {
        return Result.success(channelComponent.loadChannelReleaseStatus(param.getArticleId(), param.getPlateId()));
    }

    @Override
    public int loadArticleExist(String articleId) {
        return articleMapper.loadArticleExist(articleId);
    }

    @Override
    @Transactional(transactionManager = "txManager", propagation = Propagation.REQUIRED, rollbackFor = {java.lang.Exception.class})
    public Result saveArticleData(ArticleParam param, Users users) {
        log.info("===============开始保存文章========================");
        // 进行发布频道验证
        if (param.getArticleStatus() == 1 && null != param.getPublishChannel() && param.getPublishChannel().size() > 0){
            for (ArticlePublishChannelParam item: param.getPublishChannel()){
                if (item.getRecommendStatus() == 1){
                    Integer channelConfig = channelConfigMapper.loadTitleTypeConfig(item.getChannelId());// 某个频道的标题配置
                    boolean temp = true;
                    for (ArticleTitleDataParam title: param.getArticleTitleList()){
                        if (title.getArticleTitleTypeValue().equals(channelConfig)){
                            temp = false;
                            break;
                        }
                    }
                    // 判定是否有当前频道对应的标题类型
                    if (temp){
                        log.info("没有选择频道对应的标题类型 channelId={}", item.getChannelId());
                        return Result.error(400,"所选发布频道对应的标题类型不完整，无法进行文章发布",null);
                    }
                }
            }
        }
        // 保存主表信息
        saveArticleData(param.getArticleId(), users.getUserid(), param.getArticleTitle(), param.getArticleAuthor(), param.getArticlePromoterStatus(), param.getArticlePromoter(),
                param.getArticleScout(), param.getArticleEditor(), param.getArticleSource(), param.getArticleKeyWord(), param.getArticlePaperStatus(), param.getArticleWeChatStatus(),
                param.getArticleEBookStatus(), param.getArticleOutLinkStatus(), param.getArticleOutLink(), param.getArticleInfoStatus(), param.getArticleInfo(), param.getArticleAnnotationStatus(), param.getArticleType(),
                param.getArticleLikeRecommendStatus(), param.getArticleRecommendType(), param.getArticleRecommend(),
                param.getArticleVip(), param.getArticleVipType(), param.getArticleMoney(), param.getArticlePrice(), param.getArticleLikeType(), param.getArticleLikeCount(),
                param.getArticleCommentId(), param.getArticleCommentStatus(), param.getArticleStatus(), param.getPublicTime(),param.getArticleVideoStatus(),param.getArticleIsOriginal());
        // 处理文章刊登信息
        if (param.getArticlePaperStatus() == 1 || param.getArticleWeChatStatus() == 1) {
            articleProceedInfoService.saveArticleProceedInfoData(param.getArticleId(), param.getPeriodsNumber(), param.getLayout(), param.getProceedTime(), param.getProceedWeChat());
        }
        // 处理标题列表数据
        if (null != param.getArticleTitleList() && param.getArticleTitleList().size() > 0) {
            param.getArticleTitleList().forEach(item -> articleTitleService.saveArticleTitleData(param.getArticleId(), item.getArticleTitleTypeValue(), item.getArticleTitleValue(), item.getArticleImageId(),
                    item.getArticleImage(), item.getArticleImageAltValue()));
        }
        // 处理附件列表数据
        if (null != param.getArticleAttachmentList() && param.getArticleAttachmentList().size() > 0) {
            param.getArticleAttachmentList().forEach(item -> articleAdjunctService.saveArticleAdjunctData(users.getUserid(), param.getArticleId(), item.getAdjunctName(), item.getAdjunctUrl(), item.getShowIndex()));
        }
        // 保存文章子数据
        switch (param.getArticleType()) {
            case 2:// 法律法规
                // 保存法律基础信息
                articleLawService.saveArticleLawData(param.getArticleId(), param.getArticleLawParam().getLawTimeliness(), param.getArticleLawParam().getLawReferenceSource(), param.getArticleLawParam().getLawReferenceYear(),
                        param.getArticleLawParam().getLawReferenceNumber(), param.getArticleLawParam().getLawReplaceStatus(), param.getArticleLawParam().getLawReplace(),
                        param.getArticleLawParam().getLawIssueUnit(), param.getArticleLawParam().getLawClass(), param.getArticleLawParam().getLawLevel(), param.getArticleLawParam().getLawIssueTime(),
                        param.getArticleLawParam().getLawImplementTime(), param.getArticleLawParam().getLawOverdueTime(), param.getArticleLawParam().getLawEntryLevel(),
                        param.getArticleLawParam().getLawEntryStatus(), param.getArticleLawParam().getLawEntryPageStatus(), param.getArticleLawParam().getLawPrefixStatus(), param.getArticleLawParam().getLawPrefix());
                // 保存法律词条信息
                param.getArticleLawParam().getLawEntryList().forEach(item1 -> {
                    // 保存第一层列表
                    ArticleLawEntry articleEntry1 = articleLawEntryService.saveArticleEntryData(0, param.getArticleId(),
                            item1.getLabel(), item1.getLevel());
                    if (null != item1.getChildren() && item1.getChildren().size() > 0) {
                        item1.getChildren().forEach(item2 -> {
                            // 保存第二层列表
                            ArticleLawEntry articleEntry2 = articleLawEntryService.saveArticleEntryData(articleEntry1.getId(), param.getArticleId(),
                                    item2.getLabel(), item2.getLevel());
                            if (null != item2.getChildren() && item2.getChildren().size() > 0) {
                                // 保存第三层列表
                                item2.getChildren().forEach(item3 -> {
                                    ArticleLawEntry articleEntry3 = articleLawEntryService.saveArticleEntryData(articleEntry2.getId(), param.getArticleId(),
                                            item3.getLabel(), item3.getLevel());
                                    if (null != item3.getChildren() && item3.getChildren().size() > 0) {
                                        item3.getChildren().forEach(item4 -> {
                                            // 保存第四层列表
                                            ArticleLawEntry articleEntry4 = articleLawEntryService.saveArticleEntryData(articleEntry3.getId(), param.getArticleId(),
                                                    item4.getLabel(), item4.getLevel());
                                            if (null != item4.getChildren() && item4.getChildren().size() > 0) {
                                                item4.getChildren().forEach(item5 -> {
                                                    // 保存第五层列表
                                                    articleLawEntryService.saveArticleEntryData(articleEntry4.getId(), param.getArticleId(),
                                                            item5.getLabel(), item5.getLevel());
                                                });
                                            }
                                        });
                                    }
                                });
                            }
                        });
                    }
                });
                break;
            case 3:// 案例点评
                param.getArticleCaseParam().forEach(item -> articleCaseService.saveArticleCaseData(param.getArticleId(), item.getTitle(), item.getContent()));
                break;
            case 4:// 图集资讯
                param.getArticleImageParam().forEach(item -> articleImageService.saveArticleImageData(param.getArticleId(), item.getImageId(), item.getImageUrl(), item.getImageInfo(), item.getImageAlt(), item.getShowIndex()));
                break;
            case 5:// 政采周报(音频)
            case 6:// 亚利聊政采
                // (政采周报/聊政采)采用相同的接口
                articleAudioService.saveArticleAudioData(param.getArticleId(), param.getArticleAudioParam().getAudioIssue(), param.getArticleAudioParam().getAudioInfoStatus(),
                        param.getArticleAudioParam().getAudioInfo(), param.getArticleAudioParam().getAudioId(), param.getArticleAudioParam().getAudioName(), param.getArticleAudioParam().getAudioUrl(),
                        param.getArticleAudioParam().getAudioTime(), param.getArticleAudioParam().getAudioContent());
                break;
            case 7:// 产品
                articleProductService.saveArticleProductData(param.getArticleId(), param.getArticleProductParam().getProductChannelId(), param.getArticleProductParam().getProductName(),
                        param.getArticleProductParam().getProductPrice(), param.getArticleProductParam().getProductModel(), param.getArticleProductParam().getProductPurpose(),
                        param.getArticleProductParam().getProductImageId(), param.getArticleProductParam().getProductImage(), param.getArticleProductParam().getProductContent());
                break;
            case 8:// 图书
                articleBookService.saveArticleBookData(param.getArticleId(), param.getArticleBookParam().getBookPrice(), param.getArticleBookParam().getBookImageId(), param.getArticleBookParam().getBookImage(), param.getArticleBookParam().getBookContent());
                break;
            case 14:// 专题
                // 保存专题布局信息
                param.getArticleSpecialParam().forEach(item -> {
                    ArticleSpecialLayout layout = articleSpecialLayoutService.saveArticleSpecialLayoutData(param.getArticleId(), item.getSpecialType(), item.getSpecialStatus());
                    // 保存当前布局下的对应数据，因为有的是列表，有的是单结构，所以统一Wie列表结构
                    item.getArticleSpecialDataParamList().forEach(info -> {
                        String articleUrl = "";
                        Article article = articleMapper.loadArticle(info.getArticleId());
                        if (null != article) {
                            articleUrl = article.getArticleOutLinkStatus() == 1 ? article.getArticleOutLink() : article.getArticleUrl();
                        }
                        articleSpecialDataService.saveArticleSpecialData(layout.getId(), info.getBannerId(), info.getBannerImage(), info.getBannerAlt(), info.getBannerLink(),
                                info.getTitle(), info.getTitleStatus(), info.getTitleContent(), info.getArticleId(), info.getArticleTitle(), info.getArticleInfo(), info.getArticleImageId(),
                                info.getArticleImage(), info.getArticleImageAlt(), articleUrl, info.getContentTitle(), info.getContent());
                    });
                });
                // 处理专题注释条数据
                if (null != param.getArticleSpecialAnnotationList() && param.getArticleSpecialAnnotationList().size() > 0) {
                    param.getArticleSpecialAnnotationList().forEach(item -> articleSpecialAnnotationService.saveArticleSpecialAnnotationData(param.getArticleId(), item.getTitle(), item.getContent()));
                }
                break;
            default:
                // 文章新闻、内控制度、采购文件范本、采购合同范本、处理信息库(名库)、词库(政采百科)
                articleInformationService.saveArticleInformationData(param.getArticleId(), param.getArticleContent());
        }
        // 保存文章操作历史记录（创建-暂存/创建-发布）
        int actionType = 1;
        String articleStatus;
        if (param.getArticleStatus() == 1) {
            actionType = 2;
            articleStatus = "创建-发布";
        } else {
            articleStatus = "创建-暂存";
        }
        auditDataService.saveAuditData(users.getUserid(), param.getArticleId(), actionType, articleStatus);
        // 处理文章在发布状态下的逻辑
        if (param.getArticleStatus() == 1) {
            // 进行文章频道自动发布逻辑处理
            if (null != param.getPublishChannel() && param.getPublishChannel().size() > 0){
                param.getPublishChannel().forEach(item -> {
                    Integer channelConfig = channelConfigService.loadTitleTypeConfig(item.getChannelId());
                    channelDataService.saveChannelData(channelConfig, param.getArticleId(), item.getChannelId(), param.getArticleType(), 0, 0, 0, 0);
                });
            }
            // 发布状态下无论如何都发布到RSS频道
            channelDataService.saveChannelData(-1, param.getArticleId(), "-1", param.getArticleType(), 0, 0, 0, 0);
            // 获取当前文章除RSS频道以外发布的最早的记录--如果没有记录则更新RSS频道，如果有则更新最早的数据
            articleComponent.updateArticleUrl(param.getArticleId());
            // 更新文章静态页
            if (null != param.getPublishChannel() && param.getPublishChannel().size() > 0){
                param.getPublishChannel().forEach(item -> {
                    if (item.getRecommendStatus() == 1){
                        boolean result = channelService.updateChannelDataRecommend(param.getArticleId(),item.getChannelId());// 进行该数据的推荐状态修改
                        log.info("文章自动推荐结果 result={}", result);
                    }
                });
            }
            // 更新文章分享图
            if (param.getArticleType() != 4 && param.getArticleType() != 14) {
                String articleContent = loadArticlePreviewData(param.getArticleId());
                Map<String, Object> map = new HashMap<>();
                map.put("articleId", param.getArticleId());
                map.put("articleContent", articleContent);
                rabbitProducer.sendDefaultMessage(map);
            }
            // 新增接口在发布状态下，发送ESMQ消息
            amqpTemplate.convertAndSend(Constant.CMS_ARTICLE_QUEUE, Arrays.asList(new EsArticleMqVO(param.getArticleId(), Constant.UPDATE_ARTICLE)));
            // 如果启用了推荐作者则更新该作者的碎片
            if (param.getArticlePromoterStatus() == 1) {
                ArticlePromoter articlePromoter = articlePromoterService.selectByPrimaryKey(Integer.valueOf(param.getArticlePromoter()));
                if (null != articlePromoter) {
                    htmlBuilderComponent.buildPromoterHtml(articlePromoter);
                }
            }
        }
        log.info("===============结束保存文章========================");
        return Result.success(ResponseEnum.SUCCESS);
    }

    @Override
    public Result<PageInfo<ArticleList>> loadArticleList(ArticleListParam param, Users users) {
        // 根据填写的创建人查询创建人userId
        if (null != param.getArticleCreateUser() && !param.getArticleCreateUser().equals(""))
            param.setArticleCreateUser(userBaseInfoService.loadUserIdByName(param.getArticleCreateUser()));
        // 查询作用域处理
        if (param.getArticleScope() == 1) param.setArticleUser(users.getUserid());
        // 作者字段处理
        if (!param.getAuthor().equals("")) {
            List<String> authorStr = articlePromoterService.loadPromoterIdByName(param.getAuthor());
            if (null != authorStr && authorStr.size() > 0) {
                param.setAuthorStr(authorStr);
            } else {
                // 没有作者直接返回
                return Result.success(new PageInfo<>(new ArrayList<>()));
            }
        }
        // 关键字字段处理
        if (!param.getArticleKeyWord().equals("")) {
            List<String> wordStr = new ArrayList<>();
            String[] wordList = param.getArticleKeyWord().split(",");
            if (wordList.length > 0) {
                wordStr.addAll(Arrays.asList(wordList));
            }
            param.setWordStr(wordStr);
        }
        // 分页器处理
        PageHelper.startPage(param.getPage(), param.getSize());
        List<ArticleList> articleList = articleMapper.loadArticleList(param);
        // 遍历处理列表数据信息
        articleList.forEach(articleInfo -> {
            // 处理具体值
            articleInfo.setArticleTypeValue(articleInfo.getArticleType());
            // 处理发布位置数量
            articleInfo.setArticlePublicCount(channelDataService.loadArticleReleaseCount(articleInfo.getArticleId()));
            // 处理当前文章是否已经发布(标识是否可跳转到底层页)
            if (articleInfo.getArticleStatus() == 1 && articleInfo.getArticlePublicCount() > 0) {
                articleInfo.setArticleIsRelease(1);
            } else {
                articleInfo.setArticleIsRelease(0);
            }
            // 处理创建者昵称
            articleInfo.setArticleCreateUser(userBaseInfoService.loadUserName(articleInfo.getArticleCreateUser()));
            // 处理文章分类字典文字获取
            articleInfo.setArticleType(articleDictionaryService.loadDictionary(Integer.parseInt(articleInfo.getArticleType()), 1));
            // 获取当前文章的评论数量
            articleInfo.setCommentCount(commentService.loadCommentCountByArticle(articleInfo.getArticleId()));
            // 处理文章作者列表
            StringBuilder articleAuthor = new StringBuilder();
            if (!articleInfo.getArticleAuthor().equals("")) {
                String[] authorList = articleInfo.getArticleAuthor().split(",");
                for (String info : authorList) {
                    ArticlePromoter articlePromoter = articlePromoterService.selectByPrimaryKey(Integer.valueOf(info));
                    if (null != articlePromoter) {
                        articleAuthor.append(articlePromoter.getName());
                    }
                }
                articleInfo.setArticleAuthor(articleAuthor.toString());
            }
            // 处理报纸微信状态
            switch (articleInfo.getArticleWeChatStatus()) {
                case "-1":
                    articleInfo.setArticleWeChatStatus("未选择");
                    break;
                case "1":
                    articleInfo.setArticleWeChatStatus("已刊登");
                    break;
                case "2":
                    articleInfo.setArticleWeChatStatus("未刊登");
                    break;
            }
            switch (articleInfo.getArticleNewPaperStatus()) {
                case "-1":
                    articleInfo.setArticleNewPaperStatus("未选择");
                    break;
                case "1":
                    articleInfo.setArticleNewPaperStatus("已刊登");
                    break;
                case "2":
                    articleInfo.setArticleNewPaperStatus("未刊登");
                    break;
            }
            // 生成文章移动端连接
            if (articleInfo.getArticleOutLinkStatus() != 1){
                switch (articleInfo.getArticleTypeValue()) {// 判别正文显示类型/模板调用类型
                    case "2":// 法律
                        articleInfo.setArticleMobileUrl(law+articleInfo.getArticleId());
                        break;
                    case "3":// 案例
                        articleInfo.setArticleMobileUrl(caseUrl+articleInfo.getArticleId());
                        break;
                    case "4":// 图集
                        articleInfo.setArticleMobileUrl(atlas+articleInfo.getArticleId());
                        break;
                    case "5":// 政采周报(音频)
                    case "6":// 亚利聊政采
                        articleInfo.setArticleMobileUrl(yllzc+articleInfo.getArticleId());
                        break;
                    case "14":// 专题
                        articleInfo.setArticleMobileUrl(special+articleInfo.getArticleId());
                        break;
                    default:// 文章
                        articleInfo.setArticleMobileUrl(info+articleInfo.getArticleId());
                }
            }
        });
        PageInfo<ArticleList> list = new PageInfo<>(articleList);
        // 返回处理完成的结果数据
        return Result.success(list);
    }

    @Override
    public Result<List<ArticleExportList>> loadArticleExportList(ArticleListParam param, Users users) {
        if (param.getArticleScope() == 1) {
            param.setArticleUser(users.getUserid());
        }
        // 根据填写的创建人查询创建人userId
        if (null != param.getArticleCreateUser() && !param.getArticleCreateUser().equals(""))
            param.setArticleCreateUser(userBaseInfoService.loadUserIdByName(param.getArticleCreateUser()));
        // 作者字段处理
        if (!param.getAuthor().equals("")) {
            List<String> authorStr = articlePromoterService.loadPromoterIdByName(param.getAuthor());
            if (null != authorStr && authorStr.size() > 0) {
                param.setAuthorStr(authorStr);
            }
        }
        // 关键字字段处理
        if (!param.getArticleKeyWord().equals("")) {
            List<String> wordStr = new ArrayList<>();
            String[] wordList = param.getArticleKeyWord().split(",");
            if (wordList.length > 0) {
                wordStr.addAll(Arrays.asList(wordList));
            }
            param.setWordStr(wordStr);
        }
        List<ArticleExportList> list = articleMapper.loadArticleExportList(param);
        list.forEach(item -> {
            // 遍历处理作者名称
            List<String> author = new ArrayList<>();
            if (!item.getArticleAuthor().equals("")) {
                String[] authorList = item.getArticleAuthor().split(",");
                for (String info : authorList) {
                    String authorName = articlePromoterService.selectByPrimaryKey(Integer.valueOf(info)).getName();
                    author.add(authorName);
                }

            }
            item.setArticleAuthor(author.toString());
        });
        return Result.success(list);
    }

    @Override
    public Result<ArticleData> loadArticleData(ArticleDataParam param) {
        if (articleMapper.loadArticleExist(param.getArticleId()) == 0) return Result.error(ResponseEnum.ARTICLE_NOT_EXIST);
        ArticleData articleData = articleMapper.loadArticleData(param.getArticleId());
        // 文章发布列表获取
        List<ArticleReleaseChannelList> articleReleaseChannelList = channelDataService.loadArticleReleaseChannelList(param.getArticleId());
        articleData.setArticleReleaseChannelList(articleReleaseChannelList);
        // 处理创建用户昵称
        String createUser = userBaseInfoService.loadUserName(articleData.getArticleUserId());
        articleData.setCreateUser(createUser);
        // 获取标题列表
        List<ArticleTitleData> articleTitle = articleTitleService.loadArticleTitleList(param.getArticleId());
        articleData.setArticleTitleList(articleTitle);
        // 作者列表处理
        if (!articleData.getArticleAuthor().equals("")) {
            List<ArticleAuthorData> articleAuthorTemp = new ArrayList<>();
            String[] author = articleData.getArticleAuthor().split(",");
            for (String info : author) {
                ArticlePromoter articlePromoter = articlePromoterService.selectByPrimaryKey(Integer.valueOf(info));
                if (null != articlePromoter) {
                    ArticleAuthorData articleAuthorData = new ArticleAuthorData();
                    articleAuthorData.setId(Integer.valueOf(info));
                    articleAuthorData.setName(articlePromoter.getName());
                    articleAuthorData.setAuthorPost(articlePromoter.getAuthorPost());
                    articleAuthorTemp.add(articleAuthorData);
                }
            }
            articleData.setArticleAuthorTemp(articleAuthorTemp);
        }
        // 关键词处理
        if (!articleData.getArticleKeyWord().equals("")) {
            List<ArticleKeywordData> articleKeywordDataList = new ArrayList<>();
            String[] keyword = articleData.getArticleKeyWord().split(",");
            for (String info : keyword) {
                ArticleKeyword articleKeyword = articleKeywordService.selectByPrimaryKey(Integer.valueOf(info));
                if (null != articleKeyword) {
                    ArticleKeywordData articleKeywordData = new ArticleKeywordData();
                    articleKeywordData.setId(Integer.valueOf(info));
                    articleKeywordData.setKeyword(articleKeyword.getKeyword());
                    articleKeywordDataList.add(articleKeywordData);
                }
            }
            articleData.setArticleKeywordList(articleKeywordDataList);
        }
        // 刊登信息处理
        if (articleData.getArticlePaperStatus() == 1 || articleData.getArticleWeChatStatus() == 1) {
            ArticleProceedInfo articleProceedInfo = articleProceedInfoService.loadArticleProceedInfoData(articleData.getArticleId());
            articleData.setPeriodsNumber(articleProceedInfo.getPeriodsNumber());
            articleData.setLayout(articleProceedInfo.getLayout());
            articleData.setProceedTime(articleProceedInfo.getProceedTime());
            articleData.setProceedWeChat(articleProceedInfo.getProceedWeChat());
        }
        // 发布数量
        int articleReleaseCount = channelDataService.loadArticleReleaseCount(articleData.getArticleId());
        articleData.setArticleReleaseCount(articleReleaseCount);
        // TODO: 2020/9/7 0007 点赞数量
        articleData.setArticleReleaseLikeCount(0);
        // 额外信息处理--附件列表
        List<ArticleDataAdjunctListData> articleAdjunctList = articleAdjunctService.loadArticleAdjunctDataList(articleData.getArticleId());
        if (null != articleAdjunctList && articleAdjunctList.size() > 0) {
            articleAdjunctList.forEach(item -> {
                // 获取附件上传人昵称
                item.setUserId(userBaseInfoService.loadUserName(item.getUserId()));
            });
        }
        articleData.setArticleAdjunctList(articleAdjunctList);
        // 文章详情表获取
        if (articleData.getArticleType() == 1 || articleData.getArticleType() == 9 || articleData.getArticleType() == 10 ||
                articleData.getArticleType() == 11 || articleData.getArticleType() == 12 || articleData.getArticleType() == 13) {
            // 额外信息处理--新闻/内控制度/采购文件范本/采购合同范本/处理信息/词库
            ArticleInformation articleInformation = articleInformationService.loadArticleInformationData(articleData.getArticleId());
            if (null != articleInformation) {
                ArticleInformationData articleInformationData = new ArticleInformationData();
                articleInformationData.setArticleId(articleInformation.getArticleId());
                articleInformationData.setArticleContent(articleInformation.getArticleContent());
                articleData.setArticleInformationData(articleInformationData);
            }
        } else if (articleData.getArticleType() == 2) {
            // 额外信息处理--法律信息
            ArticleLaw articleLaw = articleLawService.loadArticleLawData(articleData.getArticleId());
            if (null != articleLaw) {
                // 处理法律词条列表
                List<ArticleDataEntryListData> list1 = articleLawEntryService.loadArticleEntryList(0, articleData.getArticleId());// 获取第一层
                if (null != list1) {
                    list1.forEach(item1 -> {
                        List<ArticleDataEntryListData> list2 = articleLawEntryService.loadArticleEntryList(item1.getId(), articleData.getArticleId());// 获取第二层
                        if (null != list2) {
                            list2.forEach(item2 -> {
                                List<ArticleDataEntryListData> list3 = articleLawEntryService.loadArticleEntryList(item2.getId(), articleData.getArticleId());// 获取第三层
                                if (null != list3) {
                                    list3.forEach(item3 -> {
                                        List<ArticleDataEntryListData> list4 = articleLawEntryService.loadArticleEntryList(item3.getId(), articleData.getArticleId());// 获取第四层
                                        if (null != list4) {
                                            list4.forEach(item4 -> {
                                                List<ArticleDataEntryListData> list5 = articleLawEntryService.loadArticleEntryList(item4.getId(), articleData.getArticleId());// 获取第四层
                                                if (null != list5) {
                                                    item4.setChildren(list5);
                                                }
                                            });
                                            item3.setChildren(list4);
                                        }
                                    });
                                }
                                item2.setChildren(list3);
                            });
                        }
                        item1.setChildren(list2);
                    });
                }
                articleLaw.setLawEntryList(list1);

                // 取代法规设置
                if (articleLaw.getLawReplaceStatus() == 1 && !articleLaw.getLawReplace().equals("")) {
                    LawReplace lawReplace = articleMapper.loadLawReplace(articleLaw.getLawReplace());
                    articleLaw.setLawReplaceData(lawReplace);
                }
            }
            articleData.setArticleLawData(articleLaw);
        } else if (articleData.getArticleType() == 3) {
            // 额外信息处理--案例
            List<ArticleCaseData> articleCaseData = articleCaseService.loadArticleCaseData(articleData.getArticleId());
            if (null != articleCaseData) {
                articleData.setArticleCaseData(articleCaseData);
            }
        } else if (articleData.getArticleType() == 4) {
            List<ArticleImageData> articleImageData = articleImageService.loadArticleImageData(articleData.getArticleId());
            if (null != articleImageData) {
                articleData.setArticleImageData(articleImageData);
            }
        } else if (articleData.getArticleType() == 5 || articleData.getArticleType() == 6) {
            // 额外信息处理--音频
            ArticleAudioData articleAudioData = articleAudioService.loadArticleAudioData(articleData.getArticleId());
            if (null != articleAudioData) {
                articleData.setArticleAudioData(articleAudioData);
            }
        } else if (articleData.getArticleType() == 7) {
            // 额外信息处理--产品
            ArticleProductData articleProductData = articleProductService.loadArticleProductData(articleData.getArticleId());
            if (null != articleProductData) {
                articleData.setArticleProductData(articleProductData);
            }
        } else if (articleData.getArticleType() == 8) {
            // 额外信息处理--图书
            ArticleBookData articleBookData = articleBookService.loadArticleBookData(articleData.getArticleId());
            if (null != articleBookData) {
                articleData.setArticleBookData(articleBookData);
            }
        } else if (articleData.getArticleType() == 14) {
            // 额外信息处理--专题
            if (articleData.getArticleAnnotationStatus() == 1) {// 获取注释轴数据
                List<ArticleSpecialAnnotationData> articleSpecialAnnotationData = articleSpecialAnnotationService.loadArticleSpecialAnnotationData(articleData.getArticleId());
                articleData.setArticleSpecialAnnotationData(articleSpecialAnnotationData);
            }
            // 获取专题配置数据
            List<ArticleSpecialLayoutData> articleSpecialLayoutData = articleSpecialLayoutService.loadArticleSpecialLayoutData(articleData.getArticleId());
            if (null != articleSpecialLayoutData) {
                // 进行遍历获取下属数据
                articleSpecialLayoutData.forEach(item -> {
                    List<ArticleSpecialData> articleSpecialData = articleSpecialDataService.loadArticleSpecialData(item.getId());
                    item.setArticleSpecialData(articleSpecialData);
                });
            }
            articleData.setArticleSpecialLayoutData(articleSpecialLayoutData);
        }
        return Result.success(articleData);
    }

    @Override
    @Transactional(transactionManager = "txManager", propagation = Propagation.REQUIRED, rollbackFor = {java.lang.Exception.class})
    public Result saveArticleAdjunct(ArticleAdjunctDataParam param, Users users) {
        // 保存文章附件表
        ArticleAdjunct articleAdjunct = articleAdjunctService.saveArticleAdjunctData(users.getUserid(), param.getArticleId(), param.getAdjunctName(),
                param.getAdjunctUrl(), param.getShowIndex());
        // 修改任何一项文章内容，发送ESMQ消息
        amqpTemplate.convertAndSend(Constant.CMS_ARTICLE_QUEUE, Collections.singletonList(new EsArticleMqVO(param.getArticleId(), Constant.UPDATE_ARTICLE)));
        // 暂定接口只返回所添加数据的ID
        return Result.success(articleAdjunct.getId());
    }

    @Override
    @Transactional(transactionManager = "txManager", propagation = Propagation.REQUIRED, rollbackFor = {java.lang.Exception.class})
    public Result deleteArticleAdjunct(ArticleAdjunctDataParam param) {
        articleAdjunctService.deleteArticleAdjunct(param.getId());
        // 修改任何一项文章内容，发送ESMQ消息
        amqpTemplate.convertAndSend(Constant.CMS_ARTICLE_QUEUE, Collections.singletonList(new EsArticleMqVO(param.getArticleId(), Constant.UPDATE_ARTICLE)));
        return Result.success(ResponseEnum.SUCCESS);
    }

    @Override
    @Transactional(transactionManager = "txManager", propagation = Propagation.REQUIRED, rollbackFor = {java.lang.Exception.class})
    public Result saveArticleTitle(ArticleTitleDataParam param) {
        // 保存文章标题
        ArticleTitle articleTitle = articleTitleService.saveArticleTitleData(param.getArticleId(), param.getArticleTitleTypeValue(), param.getArticleTitleValue(),
                param.getArticleImageId(), param.getArticleImage(), param.getArticleImageAltValue());
        // 修改任何一项文章内容，发送ESMQ消息
        amqpTemplate.convertAndSend(Constant.CMS_ARTICLE_QUEUE, Collections.singletonList(new EsArticleMqVO(param.getArticleId(), Constant.UPDATE_ARTICLE)));
        // 暂定接口只返回所添加数据的ID
        return Result.success(articleTitle.getId());
    }

    @Override
    @Transactional(transactionManager = "txManager", propagation = Propagation.REQUIRED, rollbackFor = {java.lang.Exception.class})
    public Result deleteArticleTitle(ArticleTitleDataParam param) {
        ArticleTitle articleTitle = articleTitleMapper.loadArticleTitleById(param.getId());
        if (null != articleTitle) {
            int releaseCount = articleTitleService.loadArticleTitleReleaseStatus(articleTitle.getArticleId(),articleTitle.getArticleTitleType());
            if (releaseCount > 0) {
                return Result.error(ResponseEnum.ARTICLE_TITLE_DELETE_ERROR);// 该标题已经对某个发布频道进行发布（非推荐）
            } else if (articleTitle.getArticleTitleType() == -1){
                return Result.error(ResponseEnum.ARTICLE_TITLE_DELETE_ERROR); // 必填项不可删除
            } else {
                articleTitleService.deleteArticleTitle(param.getId());
                amqpTemplate.convertAndSend(Constant.CMS_ARTICLE_QUEUE, Collections.singletonList(new EsArticleMqVO(param.getArticleId(), Constant.UPDATE_ARTICLE)));
            }
        }
        return Result.success(ResponseEnum.SUCCESS);
    }

    @Override
    @Transactional(transactionManager = "txManager", propagation = Propagation.REQUIRED, rollbackFor = {java.lang.Exception.class})
    public Result saveArticleEntry(ArticleLawEntryParam param) {
        // 保存词条结构数据
        ArticleLawEntry articleEntry = articleLawEntryService.saveArticleEntryData(param.getParentId(), param.getArticleId(),
                param.getLabel(), param.getLevel());
        // 修改任何一项文章内容，发送ESMQ消息
        amqpTemplate.convertAndSend(Constant.CMS_ARTICLE_QUEUE, Collections.singletonList(new EsArticleMqVO(param.getArticleId(), Constant.UPDATE_ARTICLE)));
        return Result.success(articleEntry.getId());
    }

    @Override
    @Transactional(transactionManager = "txManager", propagation = Propagation.REQUIRED, rollbackFor = {java.lang.Exception.class})
    public Result deleteArticleEntry(ArticleLawEntryParam param) {
        ArticleLawEntry articleEntry = articleLawEntryService.loadArticleEntry(Integer.parseInt(String.valueOf(param.getId())));
        if (null == articleEntry) return Result.error(ResponseEnum.ARTICLE_ENTRY_EXIST);// 词条结构获取失败
        switch (articleEntry.getEntryType()) {
            case 1:
                // 当前所处第一级，删除下级四层目录
                List<ArticleLawEntry> list1 = articleLawEntryService.loadArticleEntryBySuperId(articleEntry.getId());
                list1.forEach(item1 -> {// 处理第二层
                    List<ArticleLawEntry> list2 = articleLawEntryService.loadArticleEntryBySuperId(item1.getId());
                    list2.forEach(item2 -> {// 处理第三层
                        List<ArticleLawEntry> list3 = articleLawEntryService.loadArticleEntryBySuperId(item2.getId());
                        list3.forEach(item3 -> {// 处理第四层
                            List<ArticleLawEntry> list4 = articleLawEntryService.loadArticleEntryBySuperId(item3.getId());
                            list4.forEach(item4 -> {
                                articleLawEntryService.deleteArticleEntry(item4.getId());
                            });
                            articleLawEntryService.deleteArticleEntry(item3.getId());
                        });
                        articleLawEntryService.deleteArticleEntry(item2.getId());
                    });
                    articleLawEntryService.deleteArticleEntry(item1.getId());
                });
                break;
            case 2:
                // 当前所处第二级，删除下级三层目录
                List<ArticleLawEntry> list5 = articleLawEntryService.loadArticleEntryBySuperId(articleEntry.getId());
                list5.forEach(item5 -> {// 处理第二层
                    List<ArticleLawEntry> list6 = articleLawEntryService.loadArticleEntryBySuperId(item5.getId());
                    list6.forEach(item6 -> {// 处理第三层
                        List<ArticleLawEntry> list7 = articleLawEntryService.loadArticleEntryBySuperId(item6.getId());
                        list7.forEach(item7 -> {// 处理第四层
                            articleLawEntryService.deleteArticleEntry(item7.getId());
                        });
                        articleLawEntryService.deleteArticleEntry(item6.getId());
                    });
                    articleLawEntryService.deleteArticleEntry(item5.getId());
                });
                break;
            case 3:
                // 当前所处第三级，删除下级两层目录
                List<ArticleLawEntry> list8 = articleLawEntryService.loadArticleEntryBySuperId(articleEntry.getId());
                list8.forEach(item8 -> {// 处理第二层
                    List<ArticleLawEntry> list9 = articleLawEntryService.loadArticleEntryBySuperId(item8.getId());
                    list9.forEach(item9 -> {// 处理第三层
                        articleLawEntryService.deleteArticleEntry(item9.getId());
                    });
                    articleLawEntryService.deleteArticleEntry(item8.getId());
                });
                break;
            case 4:
                // 当前所处第四级，删除下级一层目录
                List<ArticleLawEntry> list10 = articleLawEntryService.loadArticleEntryBySuperId(articleEntry.getId());
                list10.forEach(item10 -> {// 处理第二层
                    articleLawEntryService.deleteArticleEntry(item10.getId());
                });
                break;
        }
        // 无论结果都删除当前层级
        articleLawEntryService.deleteArticleEntry(articleEntry.getId());
        // 修改任何一项文章内容，发送ESMQ消息
        amqpTemplate.convertAndSend(Constant.CMS_ARTICLE_QUEUE, Collections.singletonList(new EsArticleMqVO(articleEntry.getArticleId(), Constant.UPDATE_ARTICLE)));
        return Result.success(ResponseEnum.SUCCESS);
    }

    @Override
    @Transactional(transactionManager = "txManager", propagation = Propagation.REQUIRED, rollbackFor = {java.lang.Exception.class})
    public Result saveArticleSpecialAnnotation(ArticleSpecialAnnotationDataParam param) {
        ArticleSpecialAnnotation articleSpecialAnnotation = articleSpecialAnnotationService.saveArticleSpecialAnnotationData(param.getArticleId(), param.getTitle(), param.getContent());
        // 修改任何一项文章内容，发送ESMQ消息
        amqpTemplate.convertAndSend(Constant.CMS_ARTICLE_QUEUE, Collections.singletonList(new EsArticleMqVO(param.getArticleId(), Constant.UPDATE_ARTICLE)));
        return Result.success(articleSpecialAnnotation.getId());
    }

    @Override
    @Transactional(transactionManager = "txManager", propagation = Propagation.REQUIRED, rollbackFor = {java.lang.Exception.class})
    public Result deleteArticleSpecialAnnotation(ArticleSpecialAnnotationDataParam param) {
        articleSpecialAnnotationService.deleteArticleSpecialAnnotation(param.getId());
        // 修改任何一项文章内容，发送ESMQ消息
        amqpTemplate.convertAndSend(Constant.CMS_ARTICLE_QUEUE, Collections.singletonList(new EsArticleMqVO(param.getArticleId(), Constant.UPDATE_ARTICLE)));
        return Result.success(ResponseEnum.SUCCESS);
    }

    @Override
    @Transactional(transactionManager = "txManager", propagation = Propagation.REQUIRED, rollbackFor = {java.lang.Exception.class})
    public Result saveArticleImage(ArticleImageParam param) {
        ArticleImage articleImage = articleImageService.saveArticleImageData(param.getArticleId(), param.getImageId(), param.getImageUrl(), param.getImageInfo(), param.getImageAlt(), param.getShowIndex());
        // 修改任何一项文章内容，发送ESMQ消息
        amqpTemplate.convertAndSend(Constant.CMS_ARTICLE_QUEUE, Collections.singletonList(new EsArticleMqVO(param.getArticleId(), Constant.UPDATE_ARTICLE)));
        return Result.success(articleImage.getId());
    }

    @Override
    @Transactional(transactionManager = "txManager", propagation = Propagation.REQUIRED, rollbackFor = {java.lang.Exception.class})
    public Result deleteArticleImage(ArticleImageParam param) {
        articleImageService.deleteArticleImageData(param.getId());
        // 修改任何一项文章内容，发送ESMQ消息
        amqpTemplate.convertAndSend(Constant.CMS_ARTICLE_QUEUE, Collections.singletonList(new EsArticleMqVO(param.getArticleId(), Constant.UPDATE_ARTICLE)));
        return Result.success(ResponseEnum.SUCCESS);
    }

    @Override
    @Transactional(transactionManager = "txManager", propagation = Propagation.REQUIRED, rollbackFor = {java.lang.Exception.class})
    public Result updateArticleData(ArticleParam param, Users users) {
        if (articleMapper.loadArticleExist(param.getArticleId()) == 0)
            return Result.error(ResponseEnum.ARTICLE_NOT_EXIST);
        // 更新主表数据
        updateArticleData(param.getArticleId(), users.getUserid(), param.getArticleTitle(), param.getArticleAuthor(), param.getArticlePromoterStatus(), param.getArticlePromoter(),
                param.getArticleScout(), param.getArticleEditor(), param.getArticleSource(), param.getArticleKeyWord(), param.getArticlePaperStatus(), param.getArticleWeChatStatus(),
                param.getArticleEBookStatus(), param.getArticleOutLinkStatus(), param.getArticleOutLink(), param.getArticleInfoStatus(), param.getArticleInfo(), param.getArticleAnnotationStatus(), param.getArticleType(),
                param.getArticleLikeRecommendStatus(), param.getArticleRecommendType(), param.getArticleRecommend(),
                param.getArticleVip(), param.getArticleVipType(), param.getArticleMoney(), param.getArticlePrice(), param.getArticleLikeType(), param.getArticleLikeCount(),
                param.getArticleCommentId(), param.getArticleCommentStatus(), param.getArticleStatus(), param.getPublicTime(),param.getArticleVideoStatus(),param.getArticleIsOriginal());
        // 处理文章刊登信息
        if (param.getArticlePaperStatus() == 1 || param.getArticleWeChatStatus() == 1) {
            ArticleProceedInfo articleProceedInfo = articleProceedInfoService.loadArticleProceedInfoData(param.getArticleId());
            if (null == articleProceedInfo) {
                // 进行数据新增
                articleProceedInfoService.saveArticleProceedInfoData(param.getArticleId(), param.getPeriodsNumber(), param.getLayout(),
                        param.getProceedTime(), param.getProceedWeChat());
            } else {
                // 进行数据修改
                articleProceedInfoService.updateArticleProceedInfo(param.getArticleId(), param.getPeriodsNumber(), param.getLayout(),
                        param.getProceedTime(), param.getProceedWeChat());
            }
        }
        // 处理标题列表数据
        if (null != param.getArticleTitleList() && param.getArticleTitleList().size() > 0) {
            param.getArticleTitleList().forEach(item -> articleTitleService.updateArticleTitleData(item.getId(), item.getArticleTitleTypeValue(), item.getArticleTitleValue(), item.getArticleImageId(),
                    item.getArticleImage(), item.getArticleImageAltValue()));
        }
        // 更新文章子数据
        switch (param.getArticleType()) {
            case 2:// 法律法规
                // 删除资讯/案例/图集/音频/产品/图书
                articleInformationService.deleteArticleInformationData(param.getArticleId());
                articleCaseService.deleteArticleCaseAllData(param.getArticleId());
                articleImageService.deleteArticleImageByArticleId(param.getArticleId());
                articleAudioService.deleteArticleAudioByArticleId(param.getArticleId());
                articleProductService.deleteArticleProductByArticleId(param.getArticleId());
                articleBookService.deleteArticleBookByArticleId(param.getArticleId());
                // 保存法律基础信息
                articleLawService.updateArticleLawData(param.getArticleId(), param.getArticleLawParam().getLawTimeliness(), param.getArticleLawParam().getLawReferenceSource(), param.getArticleLawParam().getLawReferenceYear(),
                        param.getArticleLawParam().getLawReferenceNumber(), param.getArticleLawParam().getLawReplaceStatus(), param.getArticleLawParam().getLawReplace(),
                        param.getArticleLawParam().getLawIssueUnit(), param.getArticleLawParam().getLawClass(), param.getArticleLawParam().getLawLevel(), param.getArticleLawParam().getLawIssueTime(),
                        param.getArticleLawParam().getLawImplementTime(), param.getArticleLawParam().getLawOverdueTime(), param.getArticleLawParam().getLawEntryLevel(),
                        param.getArticleLawParam().getLawEntryStatus(), param.getArticleLawParam().getLawEntryPageStatus(), param.getArticleLawParam().getLawPrefixStatus(), param.getArticleLawParam().getLawPrefix());
                // 保存法律词条信息
                param.getArticleLawParam().getLawEntryList().forEach(item1 -> {
                    // 保存第一层列表
                    articleLawEntryService.updateArticleEntry(Integer.valueOf(String.valueOf(item1.getId())), item1.getLabel());
                    if (null != item1.getChildren() && item1.getChildren().size() > 0) {
                        item1.getChildren().forEach(item2 -> {
                            // 保存第二层列表
                            articleLawEntryService.updateArticleEntry(Integer.valueOf(String.valueOf(item2.getId())), item2.getLabel());
                            if (null != item2.getChildren() && item2.getChildren().size() > 0) {
                                // 保存第三层列表
                                item2.getChildren().forEach(item3 -> {
                                    articleLawEntryService.updateArticleEntry(Integer.valueOf(String.valueOf(item3.getId())), item3.getLabel());
                                    if (null != item3.getChildren() && item3.getChildren().size() > 0) {
                                        item3.getChildren().forEach(item4 -> {
                                            // 保存第四层列表
                                            articleLawEntryService.updateArticleEntry(Integer.valueOf(String.valueOf(item4.getId())), item4.getLabel());
                                            if (null != item4.getChildren() && item4.getChildren().size() > 0) {
                                                item4.getChildren().forEach(item5 -> {
                                                    // 保存第五层列表
                                                    articleLawEntryService.updateArticleEntry(Integer.valueOf(String.valueOf(item5.getId())), item5.getLabel());
                                                });
                                            }
                                        });
                                    }
                                });
                            }
                        });
                    }
                });
                break;
            case 3:// 案例点评
                // 删除资讯/法律/图集/音频/产品/图书
                articleInformationService.deleteArticleInformationData(param.getArticleId());
                articleLawService.deleteArticleLawData(param.getArticleId());
                articleLawEntryService.deleteArticleEntryByArticleId(param.getArticleId());
                articleImageService.deleteArticleImageByArticleId(param.getArticleId());
                articleAudioService.deleteArticleAudioByArticleId(param.getArticleId());
                articleProductService.deleteArticleProductByArticleId(param.getArticleId());
                articleBookService.deleteArticleBookByArticleId(param.getArticleId());
                // 保证案例的顺序--先删除原有的案例数据
                articleCaseService.deleteArticleCaseAllData(param.getArticleId());
                param.getArticleCaseParam().forEach(item -> articleCaseService.saveArticleCaseData(param.getArticleId(), item.getTitle(), item.getContent()));
                break;
            case 4:// 图集资讯
                // 删除资讯/法律/案例/音频/产品/图书
                articleInformationService.deleteArticleInformationData(param.getArticleId());
                articleLawService.deleteArticleLawData(param.getArticleId());
                articleLawEntryService.deleteArticleEntryByArticleId(param.getArticleId());
                articleCaseService.deleteArticleCaseAllData(param.getArticleId());
                articleAudioService.deleteArticleAudioByArticleId(param.getArticleId());
                articleProductService.deleteArticleProductByArticleId(param.getArticleId());
                articleBookService.deleteArticleBookByArticleId(param.getArticleId());
                // 保存图集数据
                param.getArticleImageParam().forEach(item -> articleImageService.updateArticleImageData(item.getId(), item.getImageId(), item.getImageUrl(), item.getImageInfo(), item.getImageAlt(), item.getShowIndex(), param.getArticleId()));
                break;
            case 5:// 政采周报(音频)
            case 6:// 亚利聊政采
                // 删除资讯/法律/案例/图集/产品/图书
                articleInformationService.deleteArticleInformationData(param.getArticleId());
                articleLawService.deleteArticleLawData(param.getArticleId());
                articleLawEntryService.deleteArticleEntryByArticleId(param.getArticleId());
                articleCaseService.deleteArticleCaseAllData(param.getArticleId());
                articleImageService.deleteArticleImageByArticleId(param.getArticleId());
                articleProductService.deleteArticleProductByArticleId(param.getArticleId());
                articleBookService.deleteArticleBookByArticleId(param.getArticleId());
                // (政采周报/聊政采)采用相同的接口
                articleAudioService.updateArticleAudioData(param.getArticleId(), param.getArticleAudioParam().getAudioIssue(), param.getArticleAudioParam().getAudioInfoStatus(),
                        param.getArticleAudioParam().getAudioInfo(), param.getArticleAudioParam().getAudioId(), param.getArticleAudioParam().getAudioName(), param.getArticleAudioParam().getAudioUrl(),
                        param.getArticleAudioParam().getAudioTime(), param.getArticleAudioParam().getAudioContent());
                break;
            case 7:// 产品
                // 删除资讯/法律/案例/图集/音频/图书
                articleInformationService.deleteArticleInformationData(param.getArticleId());
                articleLawService.deleteArticleLawData(param.getArticleId());
                articleLawEntryService.deleteArticleEntryByArticleId(param.getArticleId());
                articleCaseService.deleteArticleCaseAllData(param.getArticleId());
                articleImageService.deleteArticleImageByArticleId(param.getArticleId());
                articleAudioService.deleteArticleAudioByArticleId(param.getArticleId());
                articleBookService.deleteArticleBookByArticleId(param.getArticleId());
                // 产品信息
                articleProductService.updateArticleProductData(param.getArticleId(), param.getArticleProductParam().getProductChannelId(), param.getArticleProductParam().getProductName(),
                        param.getArticleProductParam().getProductPrice(), param.getArticleProductParam().getProductModel(), param.getArticleProductParam().getProductPurpose(),
                        param.getArticleProductParam().getProductImageId(), param.getArticleProductParam().getProductImage(), param.getArticleProductParam().getProductContent());
                break;
            case 8:// 图书
                // 删除资讯/法律/案例/图集/音频/产品
                articleInformationService.deleteArticleInformationData(param.getArticleId());
                articleLawService.deleteArticleLawData(param.getArticleId());
                articleLawEntryService.deleteArticleEntryByArticleId(param.getArticleId());
                articleCaseService.deleteArticleCaseAllData(param.getArticleId());
                articleImageService.deleteArticleImageByArticleId(param.getArticleId());
                articleAudioService.deleteArticleAudioByArticleId(param.getArticleId());
                articleProductService.deleteArticleProductByArticleId(param.getArticleId());
                // 图书
                articleBookService.updateArticleBookData(param.getArticleId(), param.getArticleBookParam().getBookPrice(), param.getArticleBookParam().getBookImageId(), param.getArticleBookParam().getBookImage(), param.getArticleBookParam().getBookContent());
                break;
            case 14:// 专题--因为专题结构特殊，在修改的时候直接清除数据，然后保存新的数据
                List<ArticleSpecialLayoutData> list = articleSpecialLayoutService.loadArticleSpecialLayoutData(param.getArticleId());
                list.forEach(oldItem -> {
                    articleSpecialDataService.deleteArticleSpecialData(oldItem.getId());// 删除数据层数据
                });
                articleSpecialLayoutService.deleteArticleSpecialLayout(param.getArticleId());// 删除布局层数据
                // 保存新的布局数据
                param.getArticleSpecialParam().forEach(item -> {
                    ArticleSpecialLayout layout = articleSpecialLayoutService.saveArticleSpecialLayoutData(param.getArticleId(), item.getSpecialType(), item.getSpecialStatus());
                    // 保存当前布局下的对应数据，因为有的是列表，有的是单结构，所以统一Wie列表结构
                    item.getArticleSpecialDataParamList().forEach(info -> {
                        String articleUrl = "";
                        Article article1 = articleMapper.loadArticle(info.getArticleId());
                        if (null != article1) {
                            articleUrl = article1.getArticleOutLinkStatus() == 1 ? article1.getArticleOutLink() : article1.getArticleUrl();
                        }
                        articleSpecialDataService.saveArticleSpecialData(layout.getId(), info.getBannerId(), info.getBannerImage(), info.getBannerAlt(), info.getBannerLink(),
                                info.getTitle(), info.getTitleStatus(), info.getTitleContent(), info.getArticleId(), info.getArticleTitle(), info.getArticleInfo(), info.getArticleImageId(),
                                info.getArticleImage(), info.getArticleImageAlt(), articleUrl, info.getContentTitle(), info.getContent());
                    });
                });
                // 处理专题注释轴
                if (null != param.getArticleSpecialAnnotationList() && param.getArticleSpecialAnnotationList().size() > 0) {
                    param.getArticleSpecialAnnotationList().forEach(item -> {
                        articleSpecialAnnotationService.updateArticleSpecialAnnotationData(item);
                    });
                }
                break;
            default:// 文章新闻、内控制度、采购文件范本、采购合同范本、处理信息库(名库)、词库(政采百科)
                // 删除法律/案例/图集/音频/产品/图书
                articleLawService.deleteArticleLawData(param.getArticleId());
                articleLawEntryService.deleteArticleEntryByArticleId(param.getArticleId());
                articleCaseService.deleteArticleCaseAllData(param.getArticleId());
                articleImageService.deleteArticleImageByArticleId(param.getArticleId());
                articleAudioService.deleteArticleAudioByArticleId(param.getArticleId());
                articleProductService.deleteArticleProductByArticleId(param.getArticleId());
                articleBookService.deleteArticleBookByArticleId(param.getArticleId());
                // 更新资讯信息
                articleInformationService.updateArticleInformationData(param.getArticleId(), param.getArticleContent());
        }
        // 保存文章操作历史记录（修改-暂存/修改-发布）
        int actionType = 7;
        String articleStatus;
        if (param.getArticleStatus() == 1) {
            actionType = 8;
            articleStatus = "修改-发布";
        } else {
            articleStatus = "修改-暂存";
        }
        auditDataService.saveAuditData(users.getUserid(), param.getArticleId(), actionType, articleStatus);
        // 处理文章在发布状态下的逻辑
        if (param.getArticleStatus() == 1) {
            // 进行文章频道自动发布逻辑处理
            if (null != param.getPublishChannel() && param.getPublishChannel().size() > 0){
                param.getPublishChannel().forEach(item -> {
                    int articleReleaseStatus = channelDataService.loadArticleReleaseStatus(param.getArticleId(),item.getChannelId());
                    if (articleReleaseStatus == 0){// 未发布过当前频道可以进行数据发布
                        Integer channelConfig = channelConfigService.loadTitleTypeConfig(item.getChannelId());
                        channelDataService.saveChannelData(channelConfig, param.getArticleId(), item.getChannelId(), param.getArticleType(), 0, 0, 0, 0);
                        if (item.getRecommendStatus() == 1){
                            boolean result = channelService.updateChannelDataRecommend(param.getArticleId(),item.getChannelId());// 进行该数据的推荐状态修改
                            log.info("文章自动推荐结果 result={}", result);
                        }
                    } else {
                        ChannelData recommendStatus = channelDataService.loadArticleReleaseChannelData(param.getArticleId(),item.getChannelId());
                        if (item.getRecommendStatus() == 1 && recommendStatus.getRecommendStatus() != 1){
                            boolean result = channelService.updateChannelDataRecommend(param.getArticleId(),item.getChannelId());// 进行该数据的推荐状态修改
                            log.info("文章自动推荐结果 result={}", result);
                        } else {// 更新文章静态页
                            articleComponent.updateArticleUrl(param.getArticleId());
                        }
                    }
                });
            }
            // 更新文章分享图
            if (param.getArticleType() != 4 && param.getArticleType() != 14) {
                String articleContent = loadArticlePreviewData(param.getArticleId());
                Map<String, Object> map = new HashMap<>();
                map.put("articleId", param.getArticleId());
                map.put("articleContent", articleContent);
                rabbitProducer.sendDefaultMessage(map);
            }
            // 修改任何一项文章内容，发送ESMQ消息
            amqpTemplate.convertAndSend(Constant.CMS_ARTICLE_QUEUE, Collections.singletonList(new EsArticleMqVO(param.getArticleId(), Constant.UPDATE_ARTICLE)));
            // 如果启用了推荐作者则更新该作者的碎片
            if (param.getArticlePromoterStatus() == 1 || !param.getArticlePromoter().equals("")) {
                ArticlePromoter articlePromoter = articlePromoterService.selectByPrimaryKey(Integer.valueOf(param.getArticlePromoter()));
                if (null != articlePromoter) {
                    htmlBuilderComponent.buildPromoterHtml(articlePromoter);
                }
            }
            // 文章修改的时候，清除文章缓存(移动端请求改为从数据库获取)
            redisObjectComponent.del(param.getArticleId());
        }
        return Result.success(ResponseEnum.SUCCESS);
    }

    @Override
    @Transactional(transactionManager = "txManager", propagation = Propagation.REQUIRED, rollbackFor = {java.lang.Exception.class})
    public Result deleteArticleData(ArticleParam param, Users users) {
        // 判断当前文章是否还有剩余的推荐位
        if (channelDataService.loadArticleReleaseCount(param.getArticleId()) != 0)
            return Result.error(ResponseEnum.ARTICLE_DELETE_ERROR);
        // 进行文章主表状态修改
        articleMapper.deleteArticleData(param.getArticleId());
        // 删除文章频道数据(无推荐位状态的文章，下架所有发布数据)
        channelDataMapper.deleteChannelDataByArticle(param.getArticleId());
        // 删除文章静态页文件
        deleteFileComponent.deleteFile(param.getArticleId());
        // 删除文章分享图
        deleteFileComponent.deleteArticleShareImage(param.getArticleId());
        // 修改任何一项文章内容，发送ESMQ消息
        amqpTemplate.convertAndSend(Constant.CMS_ARTICLE_QUEUE, Collections.singletonList(new EsArticleMqVO(param.getArticleId(), Constant.DELETE_ARTICLE)));
        // 文章删除的时候，清除文章缓存(移动端请求改为从数据库获取)
        redisObjectComponent.del(param.getArticleId());
        return Result.success(ResponseEnum.SUCCESS);
    }

    @Override
    @Transactional(transactionManager = "txManager", propagation = Propagation.REQUIRED, rollbackFor = {java.lang.Exception.class})
    public Result deleteMineArticleData(ArticleParam param, Users users) {
        // 判断当前文章是否还有剩余的推荐位
        if (channelDataService.loadArticleReleaseCount(param.getArticleId()) != 0)
            return Result.error(ResponseEnum.ARTICLE_DELETE_ERROR);
        // 删除个人稿件接口增加文章创建者相同的逻辑
        Article article = articleMapper.loadArticle(param.getArticleId());
        if (!article.getArticleUserId().equals(users.getUserid()))
            return Result.error(ResponseEnum.ARTICLE_MINE_DELETE_ERROR);
        // 进行文章主表状态修改
        articleMapper.deleteArticleData(param.getArticleId());
        // 删除文章频道数据(无推荐位状态的文章，下架所有发布数据)
        channelDataMapper.deleteChannelDataByArticle(param.getArticleId());
        // 删除文章静态页文件
        deleteFileComponent.deleteFile(param.getArticleId());
        // 删除文章分享图
        deleteFileComponent.deleteArticleShareImage(param.getArticleId());
        // 修改任何一项文章内容，发送ESMQ消息
        amqpTemplate.convertAndSend(Constant.CMS_ARTICLE_QUEUE, Collections.singletonList(new EsArticleMqVO(param.getArticleId(), Constant.DELETE_ARTICLE)));
        // 文章删除的时候，清除文章缓存(移动端请求改为从数据库获取)
        redisObjectComponent.del(param.getArticleId());
        return Result.success(ResponseEnum.SUCCESS);
    }

    @Override
    @Transactional(transactionManager = "txManager", propagation = Propagation.REQUIRED, rollbackFor = {java.lang.Exception.class})
    public Result updateArticleStatus(ArticleAuditDataParam param, Users users) {
        String[] articleList = param.getArticleId().split(",");
        for (String item : articleList) {
            // 修改当前文章审核状态
            articleMapper.updateArticleStatus(item, param.getArticleAuditStatus());
            // 修改任何一项文章内容，发送ESMQ消息
            amqpTemplate.convertAndSend(Constant.CMS_ARTICLE_QUEUE, Collections.singletonList(new EsArticleMqVO(param.getArticleId(), Constant.UPDATE_ARTICLE)));
            // 文章删除的时候，清除文章缓存(移动端请求改为从数据库获取)
            redisObjectComponent.del(param.getArticleId());
        }
        return Result.success(ResponseEnum.SUCCESS);
    }

    @Override
    public Result loadArticleMaxAudioIssue(ArticleInfoParam articleInfoParam) {
        return Result.success(articleMapper.loadArticleMaxAudioIssue(articleInfoParam.getAudioType()));
    }

    @Override
    public Result loadLawArticleList(LawArticleListParam param) {
        if (!param.getAuthor().equals("")) {
            List<String> authorStr = articlePromoterService.loadPromoterIdByName(param.getAuthor());
            if (null != authorStr && authorStr.size() > 0) {
                param.setAuthorStr(authorStr);
            } else {
                // 没有作者直接返回
                return Result.success(new PageInfo<>(new ArrayList<>()));
            }
        }
        PageHelper.startPage(param.getPage(), param.getSize());
        PageInfo<LawArticleList> list = new PageInfo<>(articleMapper.loadLawArticleList(param));
        return Result.success(list);
    }

    @Override
    public Result<List<ArticleList>> loadArticleListBySelect(ArticleListParam param, Users users) {
        List<ArticleList> list = articleMapper.loadArticleListBySelect(param);
        return Result.success(list);
    }

    @Override
    public Result<List<ArticleReleaseList>> loadArticleReleaseList(ArticleDataParam param, Users users) {
        // 判断当前文章是否有发布数据
        int result = channelDataService.loadArticleReleaseCount(param.getArticleId());
        if (result == 0) return Result.error(ResponseEnum.ARTICLE_NOT_CHANNEL_DATA);
        List<ArticleReleaseList> articleReleaseList = channelDataService.loadArticleReleaseList(param.getArticleId());
        articleReleaseList.forEach(item -> {
            Channel channel1 = channelMapper.loadChannelByPlate(item.getPlateId());
            Channel channel2 = channelMapper.loadChannelByChild(item.getPlateId());
            Channel channel3 = channelMapper.loadChannelByChild(channel2.getChannelValue());
            Channel channel4 = channelMapper.loadChannelByChild(channel3.getChannelValue());
            // 填充发布频道列表名称
            item.setArticleReleaseChannel(channel4.getChannelName() + "/" + channel3.getChannelName() + "/" + channel2.getChannelName() + "/" + channel1.getChannelName());
            // 进行频道名称填充
            item.setPlateName(channel1.getChannelName());
            // 进行对应标题数据获取
            ArticleTitle articleTitle = articleTitleService.loadArticleTitle(param.getArticleId(), item.getTitleType());
            item.setArticleTitle(articleTitle.getArticleTitle());
            item.setArticleTitleImage(articleTitle.getArticleImage());
        });
        return Result.success(articleReleaseList);
    }

    @Override
    public Result loadArticlePromoterList() {
        return Result.success(articlePromoterService.loadArticlePromoterList());
    }

    @Override
    public Result loadArticleHistory(ArticleListParam param) {
        PageHelper.startPage(param.getPage(), param.getSize());
        // 查询数据列表
        PageInfo<OperatingRecordData> list = new PageInfo<>(auditDataService.loadOperatingRecordDataList(param));
        list.getList().forEach(recordData -> {
            // 遍历获取type对应的文字
            recordData.setOperationAction(articleDictionaryService.loadDictionary(Integer.parseInt(recordData.getOperationAction()), 4));
            // 获取用户昵称
            recordData.setOperationUser(userBaseInfoService.loadUserName(recordData.getOperationUser()));
        });
        return Result.success(list);

    }

    @Override
    public Result uploadAttachment(MultipartFile file, String uid) {
        String fileUrl = uploadAttachment(file);
        UploadArticleVO uploadArticleVO = new UploadArticleVO();
        uploadArticleVO.setFileUrl(fileUrl);
        uploadArticleVO.setUid(uid);
        return Result.success(uploadArticleVO);
    }

    @Override
    public Result batchUploadAttachment(MultipartFile[] files) {
        //多文件上传
        int failCount = 0;//文件上传失败数量
        int successCount = 0;//文件上传成功数量
        int fileCount = files.length;
        String[] fileUrls = new String[fileCount];
        for (int i = 0; i < files.length; i++) {
            MultipartFile file = files[i];
            String fileUrl = uploadAttachment(file);
            log.info("上传第{}个文件，上传文件源文件{}，fileUrl={}", i, file.getOriginalFilename(), fileUrl);
            if (fileUrl == null) {
                failCount++;
            } else {
                successCount++;
            }
            fileUrls[i] = fileUrl;
        }
        if (failCount == 0) {
            return Result.success(fileUrls);
        } else {
            return Result.custom(420, successCount + "个文件上传成功" + "," + failCount + "个文件上传失败", fileUrls);
        }
    }

    @Override
    public Result deleteAttachment(AttachmentParam attachmentParam) {
        boolean flag = ossComponent.deleteFromOSS(attachmentParam.getFileUrl());
        if (flag) {
            return Result.success("删除附件成功");
        } else {
            return Result.error("删除附件失败");
        }
    }

    public Result deleteArticleFromRecycle(String[] articleIds) {
        int failCount = 0;
        int successCount = 0;
        ArticleService proxy = (ArticleService) AopContext.currentProxy();
        for (String articleId : articleIds) {
            try {
                proxy.deleteArticleFromRecycle(articleId);
                successCount++;
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                failCount++;
            }
        }
        if (failCount == 0) {
            return Result.success("从回收站删除稿件库成功");
        } else {
            return Result.success(failCount + "个稿件删除失败," + successCount + "个稿件删除成功");
        }
    }

    @Transactional(rollbackFor = Throwable.class)
    public Result deleteArticleFromRecycle(String articleId) {
        //删除稿件库主表数据
        Article article = articleMapper.loadArticle(articleId);
        if (article != null && article.getArticleStatus().intValue() == -1) {//回收站中的稿件才能删除
            int count = articleMapper.deleteArticleByArticleId(articleId);
            if (count > 0) {
                //删除稿件关联表数据
                //删除t_article_adjunct
                int count0 = articleAdjunctService.deleteArticleAdjunctByArticleId(articleId);
                //删除t_article_audio
                int count1 = articleAudioService.deleteArticleAudioByArticleId(articleId);
                //删除t_article_book
                int count2 = articleBookService.deleteArticleBookByArticleId(articleId);
                //删除t_article_case
                articleCaseService.deleteArticleCaseAllData(articleId);
                //删除t_article_html
                int count3 = articleHtmlService.deleteArticleHtmlByArticleId(articleId);
                //删除t_article_image
                int count4 = articleImageService.deleteArticleImageByArticleId(articleId);
                //删除t_article_information
                articleInformationService.deleteArticleInformationData(articleId);
                //删除t_article_law
                articleLawService.deleteArticleLawData(articleId);
                //删除t_article_law_entry
                int count5 = articleLawEntryService.deleteArticleEntryByArticleId(articleId);
                //删除t_article_proceed_info
                int count6 = articleProceedInfoService.deleteArticleProceedInfoByArticleId(articleId);
                //删除t_article_product
                int count7 = articleProductService.deleteArticleProductByArticleId(articleId);
                //删除t_article_special_annotation
                int count8 = articleSpecialAnnotationService.deleteArticleSpecialAnnotationByArticleId(articleId);
                //删除t_article_special_data
                int count9 = articleSpecialDataService.deleteArticleSpecialDataByArticleId(articleId);
                //删除t_article_special_layout
                articleSpecialLayoutService.deleteArticleSpecialLayout(articleId);
                //删除t_article_statistics
                int count10 = articleStatisticsMapper.deleteArticleStatisticsByArticleId(articleId);
                //删除t_article_title
                int count11 = articleTitleService.deleteArticleTitleByArticleId(articleId);
                log.info("删除稿件库关联表count0={}, count1={}, count2={}, count3={}, count4={}, count5={}, count6={}, count7={}," +
                                "count8={}, count9={}, count10={}, count11={}", count0, count1, count2, count3, count4, count5, count6, count7,
                        count8, count9, count10, count11);
                return Result.success("从回收站删除稿件成功");
            } else {
                return Result.error("从回收站删除稿件失败", "从回收站删除稿件失败");
            }
        } else {
            log.info("该稿件不是回收站中的稿件，不能删除，articleId={}", articleId);
            return Result.error("该稿件不是回收站中的稿件，不能删除", "该稿件不是回收站中的稿件，不能删除");
        }
    }

    public Result restoreArticleFromRecycle(String[] articleIds) {
        int failCount = 0;
        int successCount = 0;
        ArticleService proxy = (ArticleService) AopContext.currentProxy();
        for (String articleId : articleIds) {
            try {
                proxy.restoreArticleFromRecycle(articleId);
                successCount++;
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                failCount++;
            }
        }
        if (failCount == 0) {
            return Result.success("从回收站恢复稿件库成功");
        } else {
            return Result.success(failCount + "个稿件恢复失败," + successCount + "个稿件恢复成功");
        }
    }

    @Transactional(rollbackFor = Throwable.class)
    public Result restoreArticleFromRecycle(String articleId) {
        Article article = articleMapper.loadArticle(articleId);
        if(article!=null){
            int count = 0;
            if(article.getArticleCreateSource().intValue()!=0){//采集的文章
                count = articleMapper.updateArticleStatus(articleId, 1);//采集的文章恢复成审核通过状态
            }else{
                count = articleMapper.updateArticleStatus(articleId, 3);//编辑上传的文章恢复为草稿状态
            }
            if (count > 0) {
                return Result.success("从回收站恢复稿件成功");
            } else {
                return Result.error("从回收站恢复稿件失败", "从回收站恢复稿件失败");
            }
        }else{
            return Result.error("回收站中没有这篇文章", "回收站中没有这篇文章");
        }
    }

    public Result clearArticleFromRecycle() {
        int failCount = 0;
        int successCount = 0;
        ArticleService proxy = (ArticleService) AopContext.currentProxy();
        //获取稿件库回收站所有稿件
        List<Article> articleList = this.listArticleInRecycle();
        for (Article article : articleList) {
            String articleId = article.getArticleId();
            try {
                proxy.deleteArticleFromRecycle(articleId);
                successCount++;
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                failCount++;
            }
        }
        if (failCount == 0) {
            return Result.success("从回收站清空稿件库成功");
        } else {
            return Result.success(failCount + "个稿件清除失败," + successCount + "个稿件清除成功");
        }
    }

    @Override
    @Transactional(transactionManager = "txManager", propagation = Propagation.REQUIRED, rollbackFor = {java.lang.Exception.class})
    public Result addArticleKeywords(List<ArticleKeywordParam> params) {
        //TODO 数据存在redis中
        //List<ArticleKeyword> keywords = articleKeywordMapper.findAllArticleKeywords();
        params.forEach(ArticleKeywordParam -> {
            ArticleKeyword articleKeyword = articleKeywordMapper.findArticleKeywordsByKeyword(ArticleKeywordParam.getKeyword());
            if (articleKeyword != null) {
                throw new DuplicateDataException(ResponseEnum.DUPLICATE_KEYWORD_ERROR);
            }
            ArticleKeyword articleAlias = articleKeywordMapper.findArticleAlias(ArticleKeywordParam.getKeyword());
            if (articleAlias != null) {
                throw new DuplicateDataException(ResponseEnum.DUPLICATE_KEYWORD_ERROR);
            }

            if (!StringUtils.isEmpty(ArticleKeywordParam.getAlias())) {
                ArticleKeyword keywordAlias = articleKeywordMapper.findArticleKeyword(ArticleKeywordParam.getAlias());
                if (keywordAlias != null) {
                    throw new DuplicateDataException(ResponseEnum.CONTAIN_KEYWORD_ERROR);
                }
            }
            if (!StringUtils.isEmpty(ArticleKeywordParam.getAlias())) {
                ArticleKeyword repeatAlias = articleKeywordMapper.findArticleAlias(ArticleKeywordParam.getAlias());
                if (repeatAlias != null) {
                    throw new DuplicateDataException(ResponseEnum.DUPLICATE_ALIAS_ERROR);
                }
            }
            if (ArticleKeywordParam.getKeyword().equals(ArticleKeywordParam.getAlias())) {
                throw new DuplicateDataException(ResponseEnum.DUPLICATE_ALIAS_KEYWORD_ERROR);
            }

            if (!StringUtils.isEmpty(ArticleKeywordParam.getAlias())) {
                String[] split = ArticleKeywordParam.getAlias().split(",");
                List<String> alias = Arrays.asList(split);
                List<ArticleKeyword> articleKeywords = articleKeywordMapper.findArticleKeywordsByAlias(alias);
                if (CollectionUtils.isEmpty(articleKeywords)) {
                    ArticleKeyword keyword = new ArticleKeyword();
                    keyword.setKeyword(ArticleKeywordParam.getKeyword());
                    keyword.setAlias(ArticleKeywordParam.getAlias());
                    keyword.setBriefIntro(ArticleKeywordParam.getBriefIntro());
                    String initials = PinyinUtil.getPinyinInitials(ArticleKeywordParam.getKeyword());
                    if (initials.matches("[a-zA-Z]")) {
                        keyword.setCapital(initials);
                    } else {
                        keyword.setCapital("#");
                    }
                    keyword.setStaticAddress(domain + "/web/tag-list.html?id=");
                    keyword.setCreateTime(new Date());
                    keyword.setUpdateTime(new Date());
                    articleKeywordMapper.insertSelective(keyword);
                } else {
                    throw new DuplicateDataException(ResponseEnum.DUPLICATE_ALIAS_ERROR);
                }
            } else {
                ArticleKeyword keyword = new ArticleKeyword();
                keyword.setKeyword(ArticleKeywordParam.getKeyword());
                keyword.setAlias(ArticleKeywordParam.getAlias());
                keyword.setBriefIntro(ArticleKeywordParam.getBriefIntro());
                String initials = PinyinUtil.getPinyinInitials(ArticleKeywordParam.getKeyword());
                if (initials.matches("[a-zA-Z]")) {
                    keyword.setCapital(initials);
                } else {
                    keyword.setCapital("#");
                }
                keyword.setStaticAddress(domain + "/web/tag-list.html?id=");
                keyword.setCreateTime(new Date());
                keyword.setUpdateTime(new Date());
                articleKeywordMapper.insertSelective(keyword);
            }
        });
        return Result.success(params.size());
    }

    @Override
    public Result deleteArticleKeywordByIds(ArticleKeywordParam param) {
        int deleteNum = articleKeywordMapper.deleteByCapitalAndIds(param.getCapital(), param.getIds());
        if (!CollectionUtils.isEmpty(param.getIds())) {
            param.getIds().forEach(articleId -> {
                amqpTemplate.convertAndSend(Constant.CMS_KEYWORD_QUEUE, articleId);
            });
        }
        return Result.success(deleteNum);
    }

    @Override
    public Result editArticleKeywords(ArticleKeywordParam param) {
        ArticleKeyword articleKeyword = new ArticleKeyword();
        articleKeyword.setId(param.getId());
        String initials = PinyinUtil.getPinyinInitials(param.getKeyword());
        if (initials.matches("[a-zA-Z]")) {
            articleKeyword.setCapital(initials);
        } else {
            articleKeyword.setCapital("#");
        }
        articleKeyword.setBriefIntro(param.getBriefIntro());
        articleKeyword.setKeyword(param.getKeyword());
        articleKeyword.setAlias(param.getAlias());
        articleKeyword.setUpdateTime(new Date());
        ArticleKeyword keyword = articleKeywordMapper.findArticleKeyword(param.getKeyword());
        if (keyword != null && !keyword.getId().equals(param.getId())) {
            return Result.error(ResponseEnum.DUPLICATE_KEYWORD_ERROR);
        }
        if (!StringUtils.isEmpty(param.getAlias())) {
            ArticleKeyword keywordAlias = articleKeywordMapper.findArticleKeyword(param.getAlias());
            if (keywordAlias != null && !keywordAlias.getId().equals(param.getId())) {
                return Result.custom(400, "别名与<" + keywordAlias.getKeyword() + ">关键词重复", null);
            }
        }
        if (!StringUtils.isEmpty(param.getAlias())) {
            ArticleKeyword alias = articleKeywordMapper.findArticleAlias(param.getAlias());
            if (alias != null && !alias.getId().equals(param.getId())) {
                return Result.custom(400, "别名与<" + alias.getKeyword() + ">关键词别名重复", null);
            }
        }


        ArticleKeyword articleAlias = articleKeywordMapper.findArticleAlias(param.getKeyword());
        if (articleAlias != null && !articleAlias.getId().equals(param.getId())) {
            return Result.custom(400, "关键词与<" + articleAlias.getKeyword() + ">别名重复", null);
        }

        int updateNum = articleKeywordMapper.updateByPrimaryKeySelective(articleKeyword);
        if (updateNum == 0) {
            return Result.error(ResponseEnum.KEYWORD_UPDATE_ERROR);
        }
        amqpTemplate.convertAndSend(Constant.CMS_KEYWORD_QUEUE, param.getId());
        return Result.success(updateNum);
    }

    @Override
    public Result findArticleKeywords(ArticleKeywordParam param) {
        List<ArticleKeyword> articleKeywords = articleKeywordMapper.findArticleKeywordsByParam(param);
        if (CollectionUtils.isEmpty(articleKeywords)) {
            return Result.success(Collections.emptyList());
        }
        List<ArticleKeywordVO> articleKeywordVOS = articleKeywords.stream().peek(bean -> bean.setStaticAddress(bean.getStaticAddress() + bean.getId()))
                .collect(Collectors.groupingBy(ArticleKeyword::getCapital)).entrySet().stream().sorted(Map.Entry.comparingByKey())
                .map(bean -> new ArticleKeywordVO(bean.getKey(), bean.getValue())).peek(bean -> bean.setOrder((int) bean.getCapital().toCharArray()[0] - 65)).collect(Collectors.toList());
        return Result.success(articleKeywordVOS);
    }


    @Override
    public Article saveArticleData(String articleId, String articleUserId, String articleTitle, String articleAuthor, Integer articlePromoterStatus,
                                   String articlePromoter, String articleScout, String articleEditor, String articleSource, String articleKeyWord,
                                   Integer articlePaperStatus, Integer articleWeChatStatus, Integer articleEBookStatus, Integer articleOutLinkStatus,
                                   String articleOutLink, Integer articleInfoStatus, String articleInfo, Integer articleAnnotationStatus, Integer articleType, Integer articleLikeRecommendStatus,
                                   Integer articleRecommendType, String articleRecommend, Integer articleVip, Integer articleVipType, Integer articleMoney,
                                   Integer articlePrice, Integer articleLikeType, Integer articleLikeCount, String articleCommentId, Integer articleCommentStatus, Integer articleStatus, String publicTime,
                                   Integer articleVideoStatus, Integer articleIsOriginal) {
        Article article = new Article();
        article.setArticleId(articleId);
        article.setArticleUserId(articleUserId);
        article.setArticleTitle(articleTitle);
        article.setArticleAuthor(articleAuthor);
        article.setArticlePromoterStatus(articlePromoterStatus);
        article.setArticlePromoter(articlePromoter);
        article.setArticleScout(articleScout);
        article.setArticleEditor(articleEditor);
        article.setArticleSource(articleSource);
        article.setArticleKeyWord(articleKeyWord);
        article.setArticlePaperStatus(articlePaperStatus);
        article.setArticleWeChatStatus(articleWeChatStatus);
        article.setArticleEBookStatus(articleEBookStatus);
        article.setArticleOutLinkStatus(articleOutLinkStatus);
        article.setArticleOutLink(articleOutLink);
        article.setArticleInfoStatus(articleInfoStatus);
        article.setArticleInfo(articleInfo);
        article.setArticleAnnotationStatus(articleAnnotationStatus);
        article.setArticleType(articleType);
        article.setArticleLikeRecommendStatus(articleLikeRecommendStatus);
        article.setArticleRecommendType(articleRecommendType);
        article.setArticleRecommend(articleRecommend);
        article.setArticleVip(articleVip);
        article.setArticleVipType(articleVipType);
        article.setArticleMoney(articleMoney);
        article.setArticlePrice(articlePrice);
        article.setArticleLikeType(articleLikeType);
        article.setArticleLikeCount(articleLikeCount);
        article.setArticleCommentId(articleCommentId);
        article.setArticleCommentStatus(articleCommentStatus);
        article.setArticleStatus(articleStatus);
        article.setArticleShareImage("");
        article.setPublicTime(DateUtil.stringtoDate(publicTime, "yyyy-MM-dd HH:mm:ss"));
        article.setArticleVideoStatus(articleVideoStatus);
        article.setArticleIsOriginal(articleIsOriginal);
        articleMapper.saveArticleData(article);
        return article;
    }

    @Override
    public int updateArticleData(String articleId, String articleUserId, String articleTitle, String articleAuthor, Integer articlePromoterStatus,
                                 String articlePromoter, String articleScout, String articleEditor, String articleSource, String articleKeyWord,
                                 Integer articlePaperStatus, Integer articleWeChatStatus, Integer articleEBookStatus, Integer articleOutLinkStatus,
                                 String articleOutLink, Integer articleInfoStatus, String articleInfo, Integer articleAnnotationStatus, Integer articleType, Integer articleLikeRecommendStatus,
                                 Integer articleRecommendType, String articleRecommend,
                                 Integer articleVip, Integer articleVipType, Integer articleMoney, Integer articlePrice, Integer articleLikeType, Integer articleLikeCount,
                                 String articleCommentId, Integer articleCommentStatus, Integer articleStatus, String publicTime,
                                 Integer articleVideoStatus, Integer articleIsOriginal) {
        Article article = new Article();
        article.setArticleId(articleId);
        article.setArticleUserId(articleUserId);
        article.setArticleTitle(articleTitle);
        article.setArticleAuthor(articleAuthor);
        article.setArticlePromoterStatus(articlePromoterStatus);
        article.setArticlePromoter(articlePromoter);
        article.setArticleScout(articleScout);
        article.setArticleEditor(articleEditor);
        article.setArticleSource(articleSource);
        article.setArticleKeyWord(articleKeyWord);
        article.setArticlePaperStatus(articlePaperStatus);
        article.setArticleWeChatStatus(articleWeChatStatus);
        article.setArticleEBookStatus(articleEBookStatus);
        article.setArticleOutLinkStatus(articleOutLinkStatus);
        article.setArticleOutLink(articleOutLink);
        article.setArticleInfoStatus(articleInfoStatus);
        article.setArticleInfo(articleInfo);
        article.setArticleAnnotationStatus(articleAnnotationStatus);
        article.setArticleType(articleType);
        article.setArticleLikeRecommendStatus(articleLikeRecommendStatus);
        article.setArticleRecommendType(articleRecommendType);
        article.setArticleRecommend(articleRecommend);
        article.setArticleVip(articleVip);
        article.setArticleVipType(articleVipType);
        article.setArticleMoney(articleMoney);
        article.setArticlePrice(articlePrice);
        article.setArticleLikeType(articleLikeType);
        article.setArticleLikeCount(articleLikeCount);
        article.setArticleCommentId(articleCommentId);
        article.setArticleCommentStatus(articleCommentStatus);
        article.setArticleStatus(articleStatus);
        article.setPublicTime(DateUtil.stringtoDate(publicTime, "yyyy-MM-dd HH:mm:ss"));
        article.setArticleVideoStatus(articleVideoStatus);
        article.setArticleIsOriginal(articleIsOriginal);
        return articleMapper.updateArticleData(article);
    }

    /**
     * 获取文章预览信息(目前只有生成分享图用)
     *
     * @param articleId
     * @return
     */
    @Override
    public String loadArticlePreviewData(String articleId) {
        Article article = articleMapper.loadArticle(articleId);
        String templateCode;// 模板编号
        Map<String, Object> data = new HashMap<>();// 数据字段
        // 获取碎片信息
        data.put("domain", domain);// 域名属性
        data.put("header", "");
        data.put("footer", "");
        data.put("hibuick", "");// 官微
        data.put("hotSearch", "");// 热搜排行
        data.put("hotSpecial", "");// 热点专题
        data.put("videoClassroom", "");// 视频课堂
        data.put("excellentBooks", "");// 精品好书
        data.put("rightAd", "");// 广告位
        data.put("recommendArticle", "");// 猜你喜欢(不做)
        data.put("channelName", "");// 频道名称
        data.put("channelUrl", "");// 频道名称
        data.put("columnUrl", "");// 栏目名称
        data.put("copyright", "");// 栏目名称
        // 判别内容字段--这个部分集合了文章底层页中各种类型文章的独有数据
        switch (article.getArticleType()) {// 判别正文显示类型/模板调用类型
            case 2:// 法律法规
                templateCode = "RSSLAWARTICLE";
                ArticleLaw articleLaw = articleLawService.loadArticleLawData(articleId);
                data.put("articleLaw", articleLaw);
                List<ArticleDataEntryListData> list1 = articleLawEntryService.loadArticleEntryList(0, articleId);// 获取第一层
                if (null != list1) {
                    list1.forEach(item1 -> {
                        List<ArticleDataEntryListData> list2 = articleLawEntryService.loadArticleEntryList(item1.getId(), articleId);// 获取第二层
                        if (null != list2) {
                            list2.forEach(item2 -> {
                                List<ArticleDataEntryListData> list3 = articleLawEntryService.loadArticleEntryList(item2.getId(), articleId);// 获取第三层
                                if (null != list3) {
                                    list3.forEach(item3 -> {
                                        List<ArticleDataEntryListData> list4 = articleLawEntryService.loadArticleEntryList(item3.getId(), articleId);// 获取第四层
                                        if (null != list4) {
                                            list4.forEach(item4 -> {
                                                List<ArticleDataEntryListData> list5 = articleLawEntryService.loadArticleEntryList(item4.getId(), articleId);// 获取第四层
                                                if (null != list5) {
                                                    item4.setChildren(list5);
                                                }
                                            });
                                            item3.setChildren(list4);
                                        }
                                    });
                                }
                                item2.setChildren(list3);
                            });
                        }
                        item1.setChildren(list2);
                    });
                }
                data.put("articleLawEntryList", list1);
                break;
            case 3:// 案例点评
                templateCode = "RSSCASEARTICLE";
                List<ArticleCaseData> articleCaseList = articleCaseService.loadArticleCaseData(articleId);
                data.put("articleCaseList", articleCaseList);
                break;
            case 4:// 图集资讯
                templateCode = "RSSALBUMARTICLE";
                List<ArticleImageData> articleImageList = articleImageService.loadArticleImageData(articleId);
                data.put("articleImageList", articleImageList);
                break;
            case 5:// 政采周报(音频)
            case 6:// 亚利聊政采
                templateCode = "RSSAUDIOARTICLE";
                ArticleAudioData articleAudio = articleAudioService.loadArticleAudioData(articleId);
                data.put("articleAudio", articleAudio);
                break;
            case 7:// 产品
                templateCode = "RSSNEWSARTICLE";
                ArticleProductData articleProduct = articleProductService.loadArticleProductData(articleId);
                data.put("articleContent", articleProduct.getProductContent());// 文章新闻、内控制度、采购文件范本、采购合同范本、处理信息库(名库)、词库(政采百科)
                break;
            case 8:// 图书
                templateCode = "RSSNEWSARTICLE";
                ArticleBookData articleBook = articleBookService.loadArticleBookData(articleId);
                data.put("articleContent", articleBook.getBookContent());// 文章新闻、内控制度、采购文件范本、采购合同范本、处理信息库(名库)、词库(政采百科)
                break;
            case 14:// 专题
                templateCode = "RSSSPECIALARTICLE";
                // 设置专题是否有注释轴
                data.put("articleAnnotationStatus", article.getArticleAnnotationStatus());
                // 获取专题注释轴
                List<ArticleSpecialAnnotationData> annotationList = articleSpecialAnnotationService.loadArticleSpecialAnnotationData(articleId);
                data.put("annotationList", annotationList);
                // 获取专题配置数据
                List<ArticleSpecialLayoutData> layoutDataList = articleSpecialLayoutService.loadArticleSpecialLayoutData(articleId);
                if (null != layoutDataList) {
                    // 进行遍历获取下属数据
                    layoutDataList.forEach(item -> {
                        List<ArticleSpecialData> articleSpecialData = articleSpecialDataService.loadArticleSpecialData(item.getId());
                        item.setArticleSpecialData(articleSpecialData);
                    });
                }
                // 取出前两条作为单独数组
                ArticleSpecialLayoutData layoutDataList1;// Banner+标题
                ArticleSpecialLayoutData layoutDataList2;// 其余
                List<ArticleSpecialLayoutData> layoutDataList3 = new ArrayList<>();// 其余
                if (null != layoutDataList && layoutDataList.size() > 2) {
                    layoutDataList1 = layoutDataList.get(0);
                    layoutDataList2 = layoutDataList.get(1);
                    for (int i = 2; i < layoutDataList.size(); i++) {
                        layoutDataList3.add(layoutDataList.get(i));
                    }
                } else {
                    layoutDataList1 = layoutDataList.get(0);
                    layoutDataList2 = layoutDataList.get(1);
                }
                data.put("layoutDataList1", layoutDataList1.getArticleSpecialData().get(0));
                data.put("layoutDataList2", layoutDataList2.getArticleSpecialData().get(0));
                data.put("layoutDataList3", layoutDataList3);
                break;
            default:
                templateCode = "RSSNEWSARTICLE";
                ArticleInformation articleInformation = articleInformationService.loadArticleInformationData(articleId);
                data.put("articleContent", articleInformation.getArticleContent());// 文章新闻、内控制度、采购文件范本、采购合同范本、处理信息库(名库)、词库(政采百科)
        }
        // 文章固定字段处理--这个部分集合了文章底层页中所有文章固有数据
        data.put("id", article.getArticleId());// 文章ID
        data.put("commentId", article.getArticleCommentId());// 评论ID
        data.put("commentStatus", article.getArticleCommentStatus());// 评论是否开启
        data.put("articleTitle", article.getArticleTitle());// 内文标题
        data.put("articleSource", article.getArticleSource());// 信息来源
        data.put("updateTime", new Date());// 发布时间
        data.put("createTime", new Date());// 创建时间(散列值)
        data.put("articleInfoStatus", article.getArticleInfoStatus());
        data.put("articleInfo", article.getArticleInfo());// 摘要(根据启用状态判别是否进行展示)
        data.put("articleShareImage", "");// 文章分享图
        // 作者列表处理
        List<ArticlePromoter> articleAuthorList = new ArrayList<>();
        if (!article.getArticleAuthor().equals("")) {
            String[] articleAuthor = article.getArticleAuthor().split(",");
            for (String info : articleAuthor) {
                ArticlePromoter promoter = articlePromoterService.selectByPrimaryKey(Integer.valueOf(info));
                if (null != promoter) {
                    articleAuthorList.add(promoter);
                }
            }
        }
        data.put("articleAuthorList", articleAuthorList);// 作者名字列表(数据处理)
        // 推荐作者
        data.put("articlePromoterStatus", article.getArticlePromoterStatus());// 是否启用作者推荐
        data.put("articleRecommendPromoter", article.getArticlePromoter());// 推荐作者的ID
        // 关键字列表处理
        List<ArticleKeyword> articleKeywordList = new ArrayList<>();// 关键词列表(可点击)
        List<String> keywords = new ArrayList<>();// 关键词列表(仅展示)
        if (!article.getArticleKeyWord().equals("")) {
            String[] articleKeyword = article.getArticleKeyWord().split(",");
            for (String info : articleKeyword) {
                ArticleKeyword keyword = articleKeywordMapper.selectByPrimaryKey(Integer.valueOf(info));
                if (null != keyword) {
                    articleKeywordList.add(keyword);
                    keywords.add(keyword.getKeyword());
                }
            }
        }
        data.put("articleKeywordList", articleKeywordList);// 关键词列表
        if (keywords.size() > 0) {
            data.put("keywords", String.join(",", keywords));// 关键词字符串(页头关键词字段)
        } else {
            data.put("keywords", "");// 关键词字符串(页头关键词字段)
        }
        // 进行静态页生成方法调用
        return templateComponent.buildHtml(templateCode, data);
    }

    @Override
    public Article loadArticle(String articleId) {
        return articleMapper.loadArticle(articleId);
    }

    @Override
    public List<ArticleStatisticsDay> queryArticleStatisticsDayByTime(Date startTime, Date endTime, int limit){
        return articleStatisticsMapper.queryArticleStatisticsDayByTime(startTime, endTime, limit);
    }

    @Override
    public int deleteArticleStatisticsByTime(Date historyTime){
        return articleStatisticsMapper.deleteArticleStatisticsByTime(historyTime);
    }

    @Override
    public int updateArticleUrl(String articleId, String url) {
        return articleMapper.updateArticleUrl(articleId, url);
    }

    private String uploadAttachment(MultipartFile file) {
        try {
            String fileName = file.getOriginalFilename();
            String fileExtension = "";
            int idx = fileName.lastIndexOf(".");
            if (idx > 0) {
                fileExtension = fileName.substring(idx);
            } else {
                log.error("上传文件错误，没有扩展名, fileName={}", fileName);
                return null;
            }

            long snowflakeId = snowflakeComponent.getInstance().nextId();
            String newFileName = snowflakeId + fileExtension;
            InputStream originInputStream = file.getInputStream();
            String strSnowflakeId = String.valueOf(snowflakeId);
            int length = strSnowflakeId.length();
            String picFolder = NewsConstant.ATTACHMENT_ROOT + "/" + strSnowflakeId.substring(length - 4, length - 2) + "/" + strSnowflakeId.substring(length - 2, length) + "/";
            log.info("picFolder={}", picFolder);
            String fileUrl = ossComponent.uploadToOSS(originInputStream, fileName, newFileName, picFolder);
            log.info("上传附件保存地址={}", fileUrl);
            return fileUrl;
        } catch (IOException e) {
            log.error(e.getMessage(), e);
            return null;
        }
    }

    @Override
    public Result<List<ArticleList>> findArticleByKeywordId(Integer articleId) {
        //根据articleId查询关键词
        ArticleKeyword articleKeyword = articleKeywordMapper.selectByPrimaryKey(articleId);
        //根据关键词查询
        List<ArticleList> list = articleMapper.findArticleByArticleKeyWord(articleKeyword.getKeyword());
        return Result.success(list);
    }

    @Override
    public Result<PageInfo<ArticleList>> findArticleByParam(ArticleDynamicParam param) {
        ArticleKeyword articleKeyword = null;
        String keywordId = null;
        if(param.getTag()!=null){
            articleKeyword = this.getArticleKeywordByKeyword(param.getTag());
            if(articleKeyword!=null){
                keywordId = articleKeyword.getId().toString();
            }
        }else{
            keywordId = param.getKeyword();
        }
        log.info("查询关键词的keywordId={}", keywordId);
        PageHelper.startPage(param.getPageNum(), param.getPageSize());
        //String keyword = param.getKeyword();
        if (StringUtils.isEmpty(keywordId)) {
            return Result.success(new PageInfo<>(new ArrayList<>()));
        }
        List<String> keywords = Arrays.asList(keywordId.split(","));
        PageInfo<ArticleList> articleList = new PageInfo<>(articleMapper.findArticleByArticleKeyWords(keywords));
        if (!CollectionUtils.isEmpty(articleList.getList())) {
            setArticlesLabelAndImg(articleList.getList());
        }
        return Result.success(articleList);

    }

    @Override
    public void setArticlesLabelAndImg(List<ArticleList> articleList) {
        List<String> articleKeyWordCodes = articleList.stream().map(ArticleList::getArticleKeyWord).collect(Collectors.toList());
        List<String> articleIds = articleList.stream().map(ArticleList::getArticleId).collect(Collectors.toList());

        List<String> articleKeyWordIds = new ArrayList<>();
        articleKeyWordCodes.forEach(articleKeyWord -> {
            if (!StringUtils.isEmpty(articleKeyWord)) {
                String[] keyWordIds = articleKeyWord.split(",");
                if (keyWordIds.length > 0) {
                    for (String keyWordId : keyWordIds) {
                        if (!articleKeyWordIds.contains(keyWordId)) {
                            articleKeyWordIds.add(keyWordId);
                        }
                    }
                }
            }
        });
        if (!CollectionUtils.isEmpty(articleKeyWordIds)) {
            List<ArticleKeyword> articleKeywords = articleKeywordMapper.findArticleKeywordsByArticleIds(articleKeyWordIds);
            Map<Integer, String> articleKeywordMap = articleKeywords.stream().collect(Collectors.toMap(ArticleKeyword::getId, ArticleKeyword::getKeyword, (k1, k2) -> k1));
            //添加文章图片地址
            List<ArticleTitleData> titleByArticleIds = articleTitleMapper.findArticleTitleDataByArticleIds(articleIds);
            Map<String, ArticleTitleData> articleMap = titleByArticleIds.stream().collect(Collectors.toMap(ArticleTitleData::getArticleId, bean -> bean, (k1, k2) -> k1));
            //遍历文章列表 赋值属性
            articleList.forEach(bean -> {
                List<KeyValueVO> newArticleKeywords = new ArrayList<>();
                String[] code = bean.getArticleKeyWord().split(",");
                List<String> newCodes = Arrays.asList(code);
                newCodes.forEach(id -> {
                    if (!StringUtils.isEmpty(id)) {
                        KeyValueVO keyValueVO = new KeyValueVO();
                        String s = articleKeywordMap.get(Integer.parseInt(id));
                        keyValueVO.setValue(id);
                        keyValueVO.setLabel(s);
                        keyValueVO.setDomain(domain);
                        if (!StringUtils.isEmpty(s)) {
                            newArticleKeywords.add(keyValueVO);
                        }
                    }
                });
                bean.setArticleKeywords(!CollectionUtils.isEmpty(newArticleKeywords) ? newArticleKeywords : Collections.emptyList());
                bean.setArticleImage(articleMap.get(bean.getArticleId()) != null ? articleMap.get(bean.getArticleId()).getArticleImage() : "");
                bean.setArticleTitle(articleMap.get(bean.getArticleId()) != null ? articleMap.get(bean.getArticleId()).getArticleTitleValue() : "");
                if (bean.getPublicTime() != null) {
                    bean.setArticleReleaseTime(bean.getPublicTime());
                }
            });
        }

        //设置TDK
        List<String> articlePlateIds = articleList.stream().map(ArticleList::getPlateId).collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(articlePlateIds)) {
            List<ChannelTdkVO> channelTdkVOS = channelMapper.findChannelByChannelValues(articlePlateIds);
            if (!CollectionUtils.isEmpty(channelTdkVOS)) {
                Map<String, ChannelTdkVO> tdkVOMap = channelTdkVOS.stream().collect(Collectors.toMap(ChannelTdkVO::getChannelValue, bean -> bean, (k1, k2) -> k1));
                articleList.forEach(bean -> {
                    ChannelTdkVO channelTdkVO = tdkVOMap.get(bean.getPlateId());
                    bean.setChannelTitle(channelTdkVO.getChannelTitle());
                    bean.setChannelKeyword(channelTdkVO.getChannelKeyword());
                    bean.setChannelDescriptions(channelTdkVO.getChannelDescriptions());
                });
            }
        }


    }

    /**
     * 前台接口
     **/
    @Override
    public Result loadHotSearchArticle(FontArticlePram pram) {
        List<HotSearchArticle> list = articleMapper.loadHotSearchArticle(pram.getPlateId());
        return Result.success(list);
    }

    @Override
    public Result loadSpecialArticleList(FontArticlePram param) {
        PageHelper.startPage(param.getPage(), param.getSize());
        PageInfo<SpecialArticleList> list = new PageInfo<>(articleMapper.loadSpecialArticleList());
        list.getList().forEach(item -> {
            // 标题处理（当前为列表查询，查询全局推荐标题列表）
            ArticleTitle articleTitle = articleTitleService.loadArticleTitle(item.getArticleId(), -1);
            item.setArticleTitle(articleTitle.getArticleTitle());
            item.setArticleTitleImage(articleTitle.getArticleImage());
            item.setArticleTitleImageAlt(articleTitle.getArticleImageAlt());
            // 遍历处理关键词
            List<ArticleKeyword> keywords = new ArrayList<>();
            if (!item.getArticleKeyWord().equals("")) {
                String[] id = item.getArticleKeyWord().split(",");
                for (String info : id) {
                    ArticleKeyword articleKeyword = articleKeywordMapper.selectByPrimaryKey(Integer.valueOf(info));
                    if (null != articleKeyword) {
                        articleKeyword.setStaticAddress(articleKeyword.getStaticAddress() + articleKeyword.getId());
                        keywords.add(articleKeyword);
                    }
                }
            }
            item.setArticleKeywordList(keywords);
        });
        return Result.success(list);
    }

    @Override
    public Result<PageInfo<ArticleList>> findArticleListByPlateId(FontArticlePram pram) {
        PageHelper.startPage(pram.getPage(), pram.getSize());
        List<String> plateIds = new ArrayList<>();
        if (!StringUtils.isEmpty(pram.getPlateIds())) {

            String[] split = pram.getPlateIds().split(",");
            plateIds = Arrays.asList(split);

        }
        if (pram.getPlateId() != null) {
            plateIds.add(pram.getPlateId().toString());
        }
        if (CollectionUtils.isEmpty(plateIds)) {
            return Result.error(ResponseEnum.PARAM_ERROR);
        }

        PageInfo<ArticleList> articles;
        if (plateIds.size() == 1 && plateIds.stream().findFirst().get().equals("-1")) {
             articles = new PageInfo<>(articleMapper.findSpecialArticleByPlateIds());
        } else {
            List<PlateIdSectionVO> plateIdSectionVOS = new ArrayList<>();
            plateIds.forEach(plateId->{
                PlateIdSectionVO plateIdSectionVO = new PlateIdSectionVO();
                int multiple = 9 - plateId.length();
                long parseLongStart = Long.parseLong(plateId);
                for (int i = 0; i < multiple; i++) {
                    parseLongStart = parseLongStart * 10;
                }
                long parseLongEnd = Long.parseLong(plateId)+1;
                for (int i = 0; i < multiple; i++) {
                    parseLongEnd = parseLongEnd * 10;
                }
                plateIdSectionVO.setPlateIdStart(parseLongStart);
                plateIdSectionVO.setPlateIdEnd(parseLongEnd);

                plateIdSectionVOS.add(plateIdSectionVO);

            });
             articles = new PageInfo<>(articleMapper.findArticleByPlateIds(plateIdSectionVOS));
        }

        if (!CollectionUtils.isEmpty(articles.getList())) {
            setArticlesLabelAndImg(articles.getList());
        }
        return Result.success(articles);
    }

    @Override
    public int saveArticleClick(String articleId) {
        return articleMapper.updateArticleClick(articleId);
    }

    @Override
    public int saveArticleClickPhone(String articleId) {
        return articleMapper.updateArticleClickPhone(articleId);
    }

    @Override
    public Result saveArticleClickCount(FontArticlePram pram) {
        if (null != pram.getIp() && !pram.getIp().equals("")) {
            // 当用户请求IP不为空的时候，进行点击量统计
            Article article = articleMapper.loadArticle(pram.getArticleId());
            if (null != article) {
                // 查看当前IP今日是否存储过点击量
                int isUV = articleStatisticsMapper.loadIsUV(pram.getArticleId(), pram.getIp());
                ArticleStatistics articleStatistics = new ArticleStatistics();
                articleStatistics.setIp(pram.getIp());
                articleStatistics.setArticleId(pram.getArticleId());
                if (isUV == 0) {
                    // 增加UV统计
                    articleStatistics.setType(2);
                    articleStatisticsMapper.saveArticleClickCount(articleStatistics);
                    // 增加文章UV量
                    articleMapper.updateArticleUVCount(pram.getArticleId());
                }
                // 增加PV统计
                articleStatistics.setType(1);
                articleStatisticsMapper.saveArticleClickCount(articleStatistics);
                // 增加文章PV量
                articleMapper.updateArticlePVCount(pram.getArticleId());
            }
        }
        return Result.success(ResponseEnum.SUCCESS);
    }

    @Override
    public Result<PageInfo<ArticleStatistics>> findArticleStatisticsByParam(FontArticlePram pram) {
        PageHelper.startPage(pram.getPage(), pram.getSize());
        PageInfo<ArticleStatistics> list = new PageInfo<>(articleStatisticsMapper.findArticleStatisticsByArticleId(pram));
        return Result.success(list);
    }

    @Override
    public Result<PageInfo<ArticleList>> findLabelArticle(LabelArticleParam param) {
        ArticleKeyword articleKeyword = articleKeywordMapper.findArticleKeywordsByKeyword(param.getLabelName());
        if (articleKeyword == null) {
            PageInfo<ArticleList> list = new PageInfo<>();
            list.setList(Collections.emptyList());
            return Result.success(list);
        }
        PageHelper.startPage(param.getPageNum(), param.getPageSize());
        PageInfo<ArticleList> articleKeyWord = new PageInfo<>(articleMapper.findArticleByArticleKeyWord(String.valueOf(articleKeyword.getId())));
        setArticlesLabelAndImg(articleKeyWord.getList());
        return Result.success(articleKeyWord);
    }

    @Override
    public Result<PageInfo<ArticleList>> findArticleAtlasByParam(FontArticlePram pram) {
        PageHelper.startPage(pram.getPage(), pram.getSize());
        PageInfo<ArticleList> articles = new PageInfo<>(articleMapper.findArticleAtlasByParam());
        setArticlesLabelAndImg(articles.getList());
        return Result.success(articles);
    }

    @Override
    public Result<PageInfo<ArticleList>> findArticleAudioByParam(FontArticlePram pram) {

        PageInfo<ArticleList> articles = new PageInfo<>(articleMapper.findArticleAudioByParam());
        setArticlesLabelAndImg(articles.getList());
        return Result.success(articles);
    }

    @Override
    public Result<ChannelTdkVO> findArticleDynamicTdk(ArticleTdkParam param) {
        //设置TDK
        if (!StringUtils.isEmpty(param.getPlateIds())) {
            String[] split = param.getPlateIds().split(",");
            if (split.length < 2) {
                ChannelTdkVO channelTdkVO = channelMapper.findChannelByChannelValue(param.getPlateIds());
                if (channelTdkVO != null) {
                    return Result.success(channelTdkVO);
                }
            } else {
                List<String> list = Arrays.asList(split);
                List<String> collect = list.stream().map(bean -> bean.substring(0, 3)).distinct().collect(Collectors.toList());
                ChannelTdkVO channelTdkVO;
                if (collect.size() == 1) {
                    channelTdkVO = channelMapper.findChannelByChannelValue(collect.stream().findFirst().orElse("101"));
                } else {
                    channelTdkVO = channelMapper.findChannelByChannelValue("101");
                }
                if (channelTdkVO != null) {
                    return Result.success(channelTdkVO);
                }
            }


        }
        if (!StringUtils.isEmpty(param.getKeyword())) {
            ChannelTdkVO channelTdkVO = channelMapper.findChannelByChannelValue(param.getKeyword());
            if (channelTdkVO != null) {
                return Result.success(channelTdkVO);
            }
        }

        return Result.success(new ChannelTdkVO());
    }

    /**
     * 从回收站删除稿件
     *
     * @param articleIds
     * @return
     */


    /**
     * 从回收站恢复稿件
     *
     * @param articleIds
     * @return
     */


    /**
     * 从回收站清空稿件
     *
     * @return
     */


    public List<Article> listArticleInRecycle() {
        return articleMapper.listArticleInRecycle();
    }

    /**
     * 通过推荐作者id获取作者文章列表，支持分页
     *
     * @param articlePromoterId
     * @param pageNum
     * @param pageSize
     * @return
     */
    public Result listArticleByArticlePromoter(Integer articlePromoterId, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        PageInfo<Article> list = new PageInfo<>(articleMapper.listArticleByArticlePromoter(articlePromoterId));
        list.getList().forEach(item -> {
            // 遍历处理关键词
            List<ArticleKeyword> keywords = new ArrayList<>();
            if (item.getArticleKeyWord() != null && !item.getArticleKeyWord().equals("")) {
                String[] id = item.getArticleKeyWord().split(",");
                for (String info : id) {
                    ArticleKeyword articleKeyword = articleKeywordMapper.selectByPrimaryKey(Integer.valueOf(info));
                    if (null != articleKeyword) {
                        keywords.add(articleKeyword);
                    }
                }
            }
            item.setArticleKeywordList(keywords);
        });

        return Result.success(list);
    }

    public Result listMyCollectionArticle(String userId, Integer pageNum, Integer pageSize) {
        String key = String.format(Constant.COLLECTION_USER_KEY, userId);
        String collectionArticleIdsJson = redisStringComponent.get(key);
        log.info("从redis中获取我的收藏文章列表，key={}, 结果={}", key, collectionArticleIdsJson);
        //如果没有收藏，返回空list
        if (collectionArticleIdsJson == null || collectionArticleIdsJson.trim().length() < 1) {
            List<ArticleList> articleLists = new ArrayList<>();
            PageInfo<ArticleList> list = new PageInfo<>(articleLists);
            list.setPageNum(pageNum);
            list.setPageSize(pageSize);
            list.setTotal(0);
            return Result.success(list);
        }
        List<String> collectionArticleIds = JSONObject.parseArray(collectionArticleIdsJson, String.class);
        Collections.reverse(collectionArticleIds);
        int totalCount = collectionArticleIds.size();
        List<String> articleIds = PageUtil.startPage(collectionArticleIds, pageNum, pageSize);
        List<ArticleList> articleLists = articleMapper.listMyCollectionArticle(articleIds);
        PageInfo<ArticleList> list = new PageInfo<>(articleLists);
        list.setPageNum(pageNum);
        list.setPageSize(pageSize);
        list.setTotal(totalCount);
        return Result.success(list);
    }

    @Override
    public Result<List<KeyValueVO>> findAllArticleLabel() {
        List<ArticleKeyword> articleKeywords = articleKeywordMapper.findAllArticleKeywords();
        if (!CollectionUtils.isEmpty(articleKeywords)) {
            List<KeyValueVO> keyValueVOS = articleKeywords.stream().map(bean -> new KeyValueVO(bean.getKeyword(), bean.getId(), domain)).collect(Collectors.toList());
            return Result.success(keyValueVOS);
        }
        return Result.success(Collections.emptyList());
    }


    @Override
    public Result loadArticleMobileInfo(FontArticlePram pram) {
        if (null == pram.getArticleId()) return Result.error(ResponseEnum.MOBILE_ARTICLE_NOT_EXIST);
        ArticleMobileInfoData article;
        // 如果数据读取不到或者文章状态不是发布状态，返回内容不存在
        boolean redisHasKey = redisObjectComponent.hasKey(pram.getArticleId());
        if (redisHasKey) {
            // 缓存中有当前KEY获取缓存中的数据
            article = (ArticleMobileInfoData) redisObjectComponent.get(pram.getArticleId());
            // 判定数据是否可用
            if (null == article || article.getArticleStatus() != 1)
                return Result.error(ResponseEnum.MOBILE_ARTICLE_NOT_EXIST);
        } else {
            // 缓存中没有当前KEY从数据库中获取
            article = articleMapper.loadArticleMobileInfo(pram.getArticleId());
            // 判定数据是否可用
            if (null == article || article.getArticleStatus() != 1)
                return Result.error(ResponseEnum.MOBILE_ARTICLE_NOT_EXIST);
            switch (article.getArticleType()) {
                case 2:// 法律法规
                    ArticleLaw articleLaw = articleLawService.loadArticleLawData(article.getArticleId());
                    if (null != articleLaw) {
                        List<ArticleDataEntryListData> list1 = articleLawEntryService.loadArticleEntryList(0, article.getArticleId());// 获取第一层
                        if (null != list1) {
                            list1.forEach(item1 -> {
                                List<ArticleDataEntryListData> list2 = articleLawEntryService.loadArticleEntryList(item1.getId(), article.getArticleId());// 获取第二层
                                if (null != list2) {
                                    list2.forEach(item2 -> {
                                        List<ArticleDataEntryListData> list3 = articleLawEntryService.loadArticleEntryList(item2.getId(), article.getArticleId());// 获取第三层
                                        if (null != list3) {
                                            list3.forEach(item3 -> {
                                                List<ArticleDataEntryListData> list4 = articleLawEntryService.loadArticleEntryList(item3.getId(), article.getArticleId());// 获取第四层
                                                if (null != list4) {
                                                    list4.forEach(item4 -> {
                                                        List<ArticleDataEntryListData> list5 = articleLawEntryService.loadArticleEntryList(item4.getId(), article.getArticleId());// 获取第四层
                                                        if (null != list5) {
                                                            item4.setChildren(list5);
                                                        }
                                                    });
                                                    item3.setChildren(list4);
                                                }
                                            });
                                        }
                                        item2.setChildren(list3);
                                    });
                                }
                                item1.setChildren(list2);
                            });
                        }
                        articleLaw.setLawEntryList(list1);
                    }
                    article.setArticleLaw(articleLaw);
                    break;
                case 3:// 案例点评
                    List<ArticleCaseData> articleCase = articleCaseService.loadArticleCaseData(article.getArticleId());
                    article.setArticleCase(articleCase);
                    break;
                case 4:// 图集资讯
                    List<ArticleImageData> articleImage = articleImageService.loadArticleImageData(article.getArticleId());
                    article.setArticleImage(articleImage);
                    break;
                case 5:// 政采周报(音频)
                case 6:// 亚利聊政采
                    ArticleAudioData articleAudio = articleAudioService.loadArticleAudioData(article.getArticleId());
                    article.setArticleAudio(articleAudio);
                    break;
                case 7:// 产品
                    ArticleProductData articleProduct = articleProductService.loadArticleProductData(article.getArticleId());
                    article.setArticleProduct(articleProduct);
                    break;
                case 8:// 图书
                    ArticleBookData articleBook = articleBookService.loadArticleBookData(article.getArticleId());
                    article.setArticleBook(articleBook);
                    break;
                case 14:// 专题
                    // 获取专题注释轴
                    List<ArticleSpecialAnnotationData> articleSpecialAnnotation = articleSpecialAnnotationService.loadArticleSpecialAnnotationData(article.getArticleId());
                    article.setArticleSpecialAnnotation(articleSpecialAnnotation);
                    // 获取专题配置数据
                    List<ArticleSpecialLayoutData> articleSpecialLayout = articleSpecialLayoutService.loadArticleSpecialLayoutData(article.getArticleId());
                    if (null != articleSpecialLayout) {
                        // 进行遍历获取下属数据
                        articleSpecialLayout.forEach(item -> {
                            List<ArticleSpecialData> articleSpecialData = articleSpecialDataService.loadArticleSpecialData(item.getId());
                            item.setArticleSpecialData(articleSpecialData);
                        });
                    }
                    article.setArticleSpecialLayout(articleSpecialLayout);
                    break;
                default:
                    ArticleInformation articleInformation = articleInformationService.loadArticleInformationData(article.getArticleId());
                    article.setArticleInformation(articleInformation);
                    break;
            }
            // 获取附件数据
            List<ArticleDataAdjunctListData> articleAdjunct = articleAdjunctService.loadArticleAdjunctDataList(pram.getArticleId());
            article.setArticleAdjunct(articleAdjunct);
            // 数据拼装完成之后将当前数据模型存到缓存中
            redisObjectComponent.set(pram.getArticleId(), article, 3600);
        }
        // 将下方内容提出到缓存之外避免更新不刷新
        // 作者列表处理
        List<ArticlePromoter> articleAuthorList = new ArrayList<>();
        if (!article.getArticleAuthor().equals("")) {
            String[] articleAuthor = article.getArticleAuthor().split(",");
            for (String info : articleAuthor) {
                ArticlePromoter promoter = articlePromoterService.selectByPrimaryKey(Integer.valueOf(info));
                if (null != promoter) {
                    articleAuthorList.add(promoter);
                }
            }
        }
        article.setArticlePromoterList(articleAuthorList);
        // 关键字列表处理
        List<ArticleKeyword> articleKeywordList = new ArrayList<>();// 关键词列表(可点击)
        if (!article.getArticleKeyWord().equals("")) {
            String[] articleKeyword = article.getArticleKeyWord().split(",");
            for (String info : articleKeyword) {
                ArticleKeyword keyword = articleKeywordMapper.selectByPrimaryKey(Integer.valueOf(info));
                if (null != keyword) {
                    articleKeywordList.add(keyword);
                }
            }
        }
        article.setArticleKeywordList(articleKeywordList);
        // 获取发布频道数据
        Channel channel = channelService.loadChannelByArticle(pram.getArticleId());
        if (null != channel) {
            // 切割前三位
            if (Long.parseLong(channel.getChannelValue()) < 200000000L){
                String id = channel.getChannelValue().substring(0, 3);
                if (id.equals("100")) {
                    channel = channelMapper.loadChannelByPlate("101");
                } else {
                    channel = channelMapper.loadChannelByPlate(id);
                }
                article.setChannel(channel);
            } else {
                article.setChannel(null);
            }
        }
        // 获取版权信息
        article.setCopyright(copyrightMapper.selectByCopyrightCode("copyrightStatement").getCopyrightValue());
        // 获取分享图信息(默认标题列表)
        ArticleTitle articleTitle = articleTitleService.loadArticleTitle(pram.getArticleId(), 24);
        if (null == articleTitle || articleTitle.getArticleImage().equals("")) {
            articleTitle = articleTitleService.loadArticleTitle(pram.getArticleId(), -1);
        }
        article.setArticleShareTitle(articleTitle);
        return Result.success(article);
    }

    @Override
    public ArticleKeyword selectKeywordByPrimaryKey(Integer id) {
        return articleKeywordMapper.selectByPrimaryKey(id);
    }

    @Override
    public int getArticleCountByArticlePromoter(Integer articlePromoterId) {
        return articleMapper.getArticleCountByArticlePromoter(articlePromoterId);
    }

    @Override
    public List<ArticleKeyword> findArticleKeywordsByIds(int[] ids) {
        return articleKeywordMapper.findArticleKeywordsByIds(ids);
    }

    @Override
    public List<Article> listLatestArticleByArticlePromoter(Integer articlePromoterId) {
        return articleMapper.listLatestArticleByArticlePromoter(articlePromoterId);
    }

    @Override
    public Result<Integer> findArticleKeywordsNumQuery(ArticleKeywordParam param) {
        ArticleKeyword keyword = articleKeywordMapper.selectByPrimaryKey(param.getId());
        if (keyword == null) {
            return Result.error(ResponseEnum.NOT_FIND_DATA);
        }
        return Result.success(articleMapper.findArticleByArticleKeyWordCount(param.getId().toString()));
    }

    @Override
    public List<String> loadArticleListByType(Integer articleType) {
        return articleMapper.loadArticleListByType(articleType);
    }

    @Override
    public List<Article> loadArticleDisposeList(Integer limit) {
        return articleMapper.loadArticleDisposeList(limit);
    }

    @Override
    public void updateArticleDisposeStatus(String articleId) {
        articleMapper.updateArticleDisposeStatus(articleId);
    }

    @Override
    public List<ChannelDataMobile> loadKeywordMobileList(List<String> keywords) {
        return articleMapper.loadKeywordMobileList(keywords);
    }

    /**
     * 根据中文关键词获取ArticleKeyword对象
     * @param keyword
     * @return
     */
    @Override
    public ArticleKeyword getArticleKeywordByKeyword(String keyword){
        return articleKeywordMapper.findArticleKeyword(keyword);
    }

    /**
     * 保存文章pv日统计数据
     * @param articleStatisticsDay
     * @return
     */
    public int saveArticleStatisticsDay(ArticleStatisticsDay articleStatisticsDay){
        return articleStatisticsDayMapper.saveArticleStatisticsDay(articleStatisticsDay);
    }

    @Override
    public List<Article> loadArticleListBySubstation(Integer substationId) {
        return articleMapper.loadArticleListBySubstation(substationId);
    }

    @Override
    public int deleteArticle(String articleId) {
        return articleMapper.deleteArticleByArticleId(articleId);
    }
}
